1 /* Test file for mpfr_nan_p, mpfr_inf_p, mpfr_number_p, mpfr_zero_p and 2 mpfr_regular_p. 3 4 Copyright 2001-2004, 2006-2018 Free Software Foundation, Inc. 5 Contributed by the AriC and Caramba projects, INRIA. 6 7 This file is part of the GNU MPFR Library. 8 9 The GNU MPFR Library is free software; you can redistribute it and/or modify 10 it under the terms of the GNU Lesser General Public License as published by 11 the Free Software Foundation; either version 3 of the License, or (at your 12 option) any later version. 13 14 The GNU MPFR Library is distributed in the hope that it will be useful, but 15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 License for more details. 18 19 You should have received a copy of the GNU Lesser General Public License 20 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 21 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 22 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 23 24 #include "mpfr-test.h" 25 26 int 27 main (void) 28 { 29 mpfr_t x; 30 31 tests_start_mpfr (); 32 33 mpfr_init (x); 34 35 /* check +infinity gives non-zero for mpfr_inf_p only */ 36 mpfr_set_ui (x, 1L, MPFR_RNDZ); 37 mpfr_div_ui (x, x, 0L, MPFR_RNDZ); 38 if (mpfr_nan_p (x) || (mpfr_nan_p) (x) ) 39 { 40 printf ("Error: mpfr_nan_p(+Inf) gives non-zero\n"); 41 exit (1); 42 } 43 if (mpfr_inf_p (x) == 0) 44 { 45 printf ("Error: mpfr_inf_p(+Inf) gives zero\n"); 46 exit (1); 47 } 48 if (mpfr_number_p (x) || (mpfr_number_p) (x) ) 49 { 50 printf ("Error: mpfr_number_p(+Inf) gives non-zero\n"); 51 exit (1); 52 } 53 if (mpfr_zero_p (x) || (mpfr_zero_p) (x) ) 54 { 55 printf ("Error: mpfr_zero_p(+Inf) gives non-zero\n"); 56 exit (1); 57 } 58 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 59 { 60 printf ("Error: mpfr_regular_p(+Inf) gives non-zero\n"); 61 exit (1); 62 } 63 64 /* same for -Inf */ 65 mpfr_neg (x, x, MPFR_RNDN); 66 if (mpfr_nan_p (x) || (mpfr_nan_p(x))) 67 { 68 printf ("Error: mpfr_nan_p(-Inf) gives non-zero\n"); 69 exit (1); 70 } 71 if (mpfr_inf_p (x) == 0) 72 { 73 printf ("Error: mpfr_inf_p(-Inf) gives zero\n"); 74 exit (1); 75 } 76 if (mpfr_number_p (x) || (mpfr_number_p)(x) ) 77 { 78 printf ("Error: mpfr_number_p(-Inf) gives non-zero\n"); 79 exit (1); 80 } 81 if (mpfr_zero_p (x) || (mpfr_zero_p)(x) ) 82 { 83 printf ("Error: mpfr_zero_p(-Inf) gives non-zero\n"); 84 exit (1); 85 } 86 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 87 { 88 printf ("Error: mpfr_regular_p(-Inf) gives non-zero\n"); 89 exit (1); 90 } 91 92 /* same for NaN */ 93 mpfr_sub (x, x, x, MPFR_RNDN); 94 if (mpfr_nan_p (x) == 0) 95 { 96 printf ("Error: mpfr_nan_p(NaN) gives zero\n"); 97 exit (1); 98 } 99 if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) 100 { 101 printf ("Error: mpfr_inf_p(NaN) gives non-zero\n"); 102 exit (1); 103 } 104 if (mpfr_number_p (x) || (mpfr_number_p) (x) ) 105 { 106 printf ("Error: mpfr_number_p(NaN) gives non-zero\n"); 107 exit (1); 108 } 109 if (mpfr_zero_p (x) || (mpfr_zero_p)(x) ) 110 { 111 printf ("Error: mpfr_number_p(NaN) gives non-zero\n"); 112 exit (1); 113 } 114 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 115 { 116 printf ("Error: mpfr_regular_p(NaN) gives non-zero\n"); 117 exit (1); 118 } 119 120 /* same for a regular number */ 121 mpfr_set_ui (x, 1, MPFR_RNDN); 122 if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) 123 { 124 printf ("Error: mpfr_nan_p(1) gives non-zero\n"); 125 exit (1); 126 } 127 if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) 128 { 129 printf ("Error: mpfr_inf_p(1) gives non-zero\n"); 130 exit (1); 131 } 132 if (mpfr_number_p (x) == 0) 133 { 134 printf ("Error: mpfr_number_p(1) gives zero\n"); 135 exit (1); 136 } 137 if (mpfr_zero_p (x) || (mpfr_zero_p) (x) ) 138 { 139 printf ("Error: mpfr_zero_p(1) gives non-zero\n"); 140 exit (1); 141 } 142 if (mpfr_regular_p (x) == 0 || (mpfr_regular_p) (x) == 0) 143 { 144 printf ("Error: mpfr_regular_p(1) gives zero\n"); 145 exit (1); 146 } 147 148 /* Same for +0 */ 149 mpfr_set_ui (x, 0, MPFR_RNDN); 150 if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) 151 { 152 printf ("Error: mpfr_nan_p(+0) gives non-zero\n"); 153 exit (1); 154 } 155 if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) 156 { 157 printf ("Error: mpfr_inf_p(+0) gives non-zero\n"); 158 exit (1); 159 } 160 if (mpfr_number_p (x) == 0) 161 { 162 printf ("Error: mpfr_number_p(+0) gives zero\n"); 163 exit (1); 164 } 165 if (mpfr_zero_p (x) == 0 ) 166 { 167 printf ("Error: mpfr_zero_p(+0) gives zero\n"); 168 exit (1); 169 } 170 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 171 { 172 printf ("Error: mpfr_regular_p(+0) gives non-zero\n"); 173 exit (1); 174 } 175 176 /* Same for -0 */ 177 mpfr_set_ui (x, 0, MPFR_RNDN); 178 mpfr_neg (x, x, MPFR_RNDN); 179 if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) 180 { 181 printf ("Error: mpfr_nan_p(-0) gives non-zero\n"); 182 exit (1); 183 } 184 if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) 185 { 186 printf ("Error: mpfr_inf_p(-0) gives non-zero\n"); 187 exit (1); 188 } 189 if (mpfr_number_p (x) == 0) 190 { 191 printf ("Error: mpfr_number_p(-0) gives zero\n"); 192 exit (1); 193 } 194 if (mpfr_zero_p (x) == 0 ) 195 { 196 printf ("Error: mpfr_zero_p(-0) gives zero\n"); 197 exit (1); 198 } 199 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 200 { 201 printf ("Error: mpfr_regular_p(-0) gives non-zero\n"); 202 exit (1); 203 } 204 205 mpfr_clear (x); 206 207 tests_end_mpfr (); 208 return 0; 209 } 210