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, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. 5 Contributed by the AriC and Caramel 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 <stdio.h> 25 #include <stdlib.h> 26 27 #include "mpfr-test.h" 28 29 int 30 main (void) 31 { 32 mpfr_t x; 33 34 tests_start_mpfr (); 35 36 mpfr_init (x); 37 38 /* check +infinity gives non-zero for mpfr_inf_p only */ 39 mpfr_set_ui (x, 1L, MPFR_RNDZ); 40 mpfr_div_ui (x, x, 0L, MPFR_RNDZ); 41 if (mpfr_nan_p (x) || (mpfr_nan_p) (x) ) 42 { 43 printf ("Error: mpfr_nan_p(+Inf) gives non-zero\n"); 44 exit (1); 45 } 46 if (mpfr_inf_p (x) == 0) 47 { 48 printf ("Error: mpfr_inf_p(+Inf) gives zero\n"); 49 exit (1); 50 } 51 if (mpfr_number_p (x) || (mpfr_number_p) (x) ) 52 { 53 printf ("Error: mpfr_number_p(+Inf) gives non-zero\n"); 54 exit (1); 55 } 56 if (mpfr_zero_p (x) || (mpfr_zero_p) (x) ) 57 { 58 printf ("Error: mpfr_zero_p(+Inf) gives non-zero\n"); 59 exit (1); 60 } 61 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 62 { 63 printf ("Error: mpfr_regular_p(+Inf) gives non-zero\n"); 64 exit (1); 65 } 66 67 /* same for -Inf */ 68 mpfr_neg (x, x, MPFR_RNDN); 69 if (mpfr_nan_p (x) || (mpfr_nan_p(x))) 70 { 71 printf ("Error: mpfr_nan_p(-Inf) gives non-zero\n"); 72 exit (1); 73 } 74 if (mpfr_inf_p (x) == 0) 75 { 76 printf ("Error: mpfr_inf_p(-Inf) gives zero\n"); 77 exit (1); 78 } 79 if (mpfr_number_p (x) || (mpfr_number_p)(x) ) 80 { 81 printf ("Error: mpfr_number_p(-Inf) gives non-zero\n"); 82 exit (1); 83 } 84 if (mpfr_zero_p (x) || (mpfr_zero_p)(x) ) 85 { 86 printf ("Error: mpfr_zero_p(-Inf) gives non-zero\n"); 87 exit (1); 88 } 89 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 90 { 91 printf ("Error: mpfr_regular_p(-Inf) gives non-zero\n"); 92 exit (1); 93 } 94 95 /* same for NaN */ 96 mpfr_sub (x, x, x, MPFR_RNDN); 97 if (mpfr_nan_p (x) == 0) 98 { 99 printf ("Error: mpfr_nan_p(NaN) gives zero\n"); 100 exit (1); 101 } 102 if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) 103 { 104 printf ("Error: mpfr_inf_p(NaN) gives non-zero\n"); 105 exit (1); 106 } 107 if (mpfr_number_p (x) || (mpfr_number_p) (x) ) 108 { 109 printf ("Error: mpfr_number_p(NaN) gives non-zero\n"); 110 exit (1); 111 } 112 if (mpfr_zero_p (x) || (mpfr_zero_p)(x) ) 113 { 114 printf ("Error: mpfr_number_p(NaN) gives non-zero\n"); 115 exit (1); 116 } 117 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 118 { 119 printf ("Error: mpfr_regular_p(NaN) gives non-zero\n"); 120 exit (1); 121 } 122 123 /* same for a regular number */ 124 mpfr_set_ui (x, 1, MPFR_RNDN); 125 if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) 126 { 127 printf ("Error: mpfr_nan_p(1) gives non-zero\n"); 128 exit (1); 129 } 130 if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) 131 { 132 printf ("Error: mpfr_inf_p(1) gives non-zero\n"); 133 exit (1); 134 } 135 if (mpfr_number_p (x) == 0) 136 { 137 printf ("Error: mpfr_number_p(1) gives zero\n"); 138 exit (1); 139 } 140 if (mpfr_zero_p (x) || (mpfr_zero_p) (x) ) 141 { 142 printf ("Error: mpfr_zero_p(1) gives non-zero\n"); 143 exit (1); 144 } 145 if (mpfr_regular_p (x) == 0 || (mpfr_regular_p) (x) == 0) 146 { 147 printf ("Error: mpfr_regular_p(1) gives zero\n"); 148 exit (1); 149 } 150 151 /* Same for +0 */ 152 mpfr_set_ui (x, 0, MPFR_RNDN); 153 if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) 154 { 155 printf ("Error: mpfr_nan_p(+0) gives non-zero\n"); 156 exit (1); 157 } 158 if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) 159 { 160 printf ("Error: mpfr_inf_p(+0) gives non-zero\n"); 161 exit (1); 162 } 163 if (mpfr_number_p (x) == 0) 164 { 165 printf ("Error: mpfr_number_p(+0) gives zero\n"); 166 exit (1); 167 } 168 if (mpfr_zero_p (x) == 0 ) 169 { 170 printf ("Error: mpfr_zero_p(+0) gives zero\n"); 171 exit (1); 172 } 173 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 174 { 175 printf ("Error: mpfr_regular_p(+0) gives non-zero\n"); 176 exit (1); 177 } 178 179 /* Same for -0 */ 180 mpfr_set_ui (x, 0, MPFR_RNDN); 181 mpfr_neg (x, x, MPFR_RNDN); 182 if (mpfr_nan_p (x) || (mpfr_nan_p)(x)) 183 { 184 printf ("Error: mpfr_nan_p(-0) gives non-zero\n"); 185 exit (1); 186 } 187 if (mpfr_inf_p (x) || (mpfr_inf_p)(x) ) 188 { 189 printf ("Error: mpfr_inf_p(-0) gives non-zero\n"); 190 exit (1); 191 } 192 if (mpfr_number_p (x) == 0) 193 { 194 printf ("Error: mpfr_number_p(-0) gives zero\n"); 195 exit (1); 196 } 197 if (mpfr_zero_p (x) == 0 ) 198 { 199 printf ("Error: mpfr_zero_p(-0) gives zero\n"); 200 exit (1); 201 } 202 if (mpfr_regular_p (x) || (mpfr_regular_p) (x) ) 203 { 204 printf ("Error: mpfr_regular_p(-0) gives non-zero\n"); 205 exit (1); 206 } 207 208 mpfr_clear (x); 209 210 tests_end_mpfr (); 211 return 0; 212 } 213