1 /* random.c -- Handle seed for random numbers. 2 3 Copyright (C) 2013 INRIA 4 5 This file is part of GNU MPC. 6 7 GNU MPC is free software; you can redistribute it and/or modify it under 8 the terms of the GNU Lesser General Public License as published by the 9 Free Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY 13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 15 more details. 16 17 You should have received a copy of the GNU Lesser General Public License 18 along with this program. If not, see http://www.gnu.org/licenses/ . 19 */ 20 21 #include "mpc-tests.h" 22 23 /* set MPFR flags to random values */ 24 void 25 set_mpfr_flags (int counter) 26 { 27 if (counter & 1) 28 mpfr_set_underflow (); 29 else 30 mpfr_clear_underflow (); 31 if (counter & 2) 32 mpfr_set_overflow (); 33 else 34 mpfr_clear_overflow (); 35 /* the divide-by-0 flag was added in MPFR 3.1.0 */ 36 #ifdef mpfr_set_divby0 37 if (counter & 4) 38 mpfr_set_divby0 (); 39 else 40 mpfr_clear_divby0 (); 41 #endif 42 if (counter & 8) 43 mpfr_set_nanflag (); 44 else 45 mpfr_clear_nanflag (); 46 if (counter & 16) 47 mpfr_set_inexflag (); 48 else 49 mpfr_clear_inexflag (); 50 if (counter & 32) 51 mpfr_set_erangeflag (); 52 else 53 mpfr_clear_erangeflag (); 54 } 55 56 /* Check MPFR flags: we allow that some flags are set internally by MPC, 57 for example if MPC does internal computations (using MPFR) which yield 58 an overflow, even if the final MPC result fits in the exponent range. 59 However we don't allow MPC to *clear* the MPFR flags */ 60 void 61 check_mpfr_flags (int counter) 62 { 63 int old, neu; 64 65 old = (counter & 1) != 0; 66 neu = mpfr_underflow_p () != 0; 67 if (old && (neu == 0)) 68 { 69 printf ("Error, underflow flag has been modified from %d to %d\n", 70 old, neu); 71 exit (1); 72 } 73 old = (counter & 2) != 0; 74 neu = mpfr_overflow_p () != 0; 75 if (old && (neu == 0)) 76 { 77 printf ("Error, overflow flag has been modified from %d to %d\n", 78 old, neu); 79 exit (1); 80 } 81 #ifdef mpfr_divby0_p 82 old = (counter & 4) != 0; 83 neu = mpfr_divby0_p () != 0; 84 if (old && (neu == 0)) 85 { 86 printf ("Error, divby0 flag has been modified from %d to %d\n", 87 old, neu); 88 exit (1); 89 } 90 #endif 91 old = (counter & 8) != 0; 92 neu = mpfr_nanflag_p () != 0; 93 if (old && (neu == 0)) 94 { 95 printf ("Error, nanflag flag has been modified from %d to %d\n", 96 old, neu); 97 exit (1); 98 } 99 old = (counter & 16) != 0; 100 neu = mpfr_inexflag_p () != 0; 101 if (old && (neu == 0)) 102 { 103 printf ("Error, inexflag flag has been modified from %d to %d\n", 104 old, neu); 105 exit (1); 106 } 107 old = (counter & 32) != 0; 108 neu = mpfr_erangeflag_p () != 0; 109 if (old && (neu == 0)) 110 { 111 printf ("Error, erangeflag flag has been modified from %d to %d\n", 112 old, neu); 113 exit (1); 114 } 115 } 116