Back to index

glibc  2.9
bug-nextafter.c
Go to the documentation of this file.
00001 #include <fenv.h>
00002 #include <math.h>
00003 #include <float.h>
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 
00007 float zero = 0.0;
00008 float inf = INFINITY;
00009 
00010 int
00011 main (void)
00012 {
00013   int result = 0;
00014 
00015   float i = INFINITY;
00016   float m = FLT_MAX;
00017   feclearexcept (FE_ALL_EXCEPT);
00018   if (nextafterf (m, i) != i)
00019     {
00020       puts ("nextafterf+ failed");
00021       ++result;
00022     }
00023   if (fetestexcept (FE_OVERFLOW) == 0)
00024     {
00025       puts ("nextafterf+ did not overflow");
00026       ++result;
00027     }
00028   feclearexcept (FE_ALL_EXCEPT);
00029   if (nextafterf (-m, -i) != -i)
00030     {
00031       puts ("nextafterf- failed");
00032       ++result;
00033     }
00034   if (fetestexcept (FE_OVERFLOW) == 0)
00035     {
00036       puts ("nextafterf- did not overflow");
00037       ++result;
00038     }
00039 
00040   i = 0;
00041   m = FLT_MIN;
00042   feclearexcept (FE_ALL_EXCEPT);
00043   i = nextafterf (m, i);
00044   if (i < 0 || i >= FLT_MIN)
00045     {
00046       puts ("nextafterf+ failed");
00047       ++result;
00048     }
00049   if (fetestexcept (FE_UNDERFLOW) == 0)
00050     {
00051       puts ("nextafterf+ did not underflow");
00052       ++result;
00053     }
00054   i = 0;
00055   feclearexcept (FE_ALL_EXCEPT);
00056   i = nextafterf (-m, -i);
00057   if (i > 0 || i <= -FLT_MIN)
00058     {
00059       puts ("nextafterf- failed");
00060       ++result;
00061     }
00062   if (fetestexcept (FE_UNDERFLOW) == 0)
00063     {
00064       puts ("nextafterf- did not underflow");
00065       ++result;
00066     }
00067   i = -INFINITY;
00068   feclearexcept (FE_ALL_EXCEPT);
00069   m = nextafterf (zero, inf);
00070   if (m < 0.0 || m >= FLT_MIN)
00071     {
00072       puts ("nextafterf+ failed");
00073       ++result;
00074     }
00075   if (fetestexcept (FE_UNDERFLOW) == 0)
00076     {
00077       puts ("nextafterf+ did not underflow");
00078       ++result;
00079     }
00080   feclearexcept (FE_ALL_EXCEPT);
00081   if (nextafterf (m, i) != 0.0)
00082     {
00083       puts ("nextafterf+ failed");
00084       ++result;
00085     }
00086   if (fetestexcept (FE_UNDERFLOW) == 0)
00087     {
00088       puts ("nextafterf+ did not underflow");
00089       ++result;
00090     }
00091   feclearexcept (FE_ALL_EXCEPT);
00092   m = nextafterf (copysignf (zero, -1.0), -inf);
00093   if (m > 0.0 || m <= -FLT_MIN)
00094     {
00095       puts ("nextafterf- failed");
00096       ++result;
00097     }
00098   if (fetestexcept (FE_UNDERFLOW) == 0)
00099     {
00100       puts ("nextafterf- did not underflow");
00101       ++result;
00102     }
00103   feclearexcept (FE_ALL_EXCEPT);
00104   if (nextafterf (m, -i) != 0.0)
00105     {
00106       puts ("nextafterf- failed");
00107       ++result;
00108     }
00109   if (fetestexcept (FE_UNDERFLOW) == 0)
00110     {
00111       puts ("nextafterf- did not underflow");
00112       ++result;
00113     }
00114 
00115   double di = INFINITY;
00116   double dm = DBL_MAX;
00117   feclearexcept (FE_ALL_EXCEPT);
00118   if (nextafter (dm, di) != di)
00119     {
00120       puts ("nextafter+ failed");
00121       ++result;
00122     }
00123   if (fetestexcept (FE_OVERFLOW) == 0)
00124     {
00125       puts ("nextafter+ did not overflow");
00126       ++result;
00127     }
00128   feclearexcept (FE_ALL_EXCEPT);
00129   if (nextafter (-dm, -di) != -di)
00130     {
00131       puts ("nextafter failed");
00132       ++result;
00133     }
00134   if (fetestexcept (FE_OVERFLOW) == 0)
00135     {
00136       puts ("nextafter- did not overflow");
00137       ++result;
00138     }
00139 
00140   di = 0;
00141   dm = DBL_MIN;
00142   feclearexcept (FE_ALL_EXCEPT);
00143   di = nextafter (dm, di);
00144   if (di < 0 || di >= DBL_MIN)
00145     {
00146       puts ("nextafter+ failed");
00147       ++result;
00148     }
00149   if (fetestexcept (FE_UNDERFLOW) == 0)
00150     {
00151       puts ("nextafter+ did not underflow");
00152       ++result;
00153     }
00154   di = 0;
00155   feclearexcept (FE_ALL_EXCEPT);
00156   di = nextafter (-dm, -di);
00157   if (di > 0 || di <= -DBL_MIN)
00158     {
00159       puts ("nextafter- failed");
00160       ++result;
00161     }
00162   if (fetestexcept (FE_UNDERFLOW) == 0)
00163     {
00164       puts ("nextafter- did not underflow");
00165       ++result;
00166     }
00167   di = -INFINITY;
00168   feclearexcept (FE_ALL_EXCEPT);
00169   dm = nextafter (zero, inf);
00170   if (dm < 0.0 || dm >= DBL_MIN)
00171     {
00172       puts ("nextafter+ failed");
00173       ++result;
00174     }
00175   if (fetestexcept (FE_UNDERFLOW) == 0)
00176     {
00177       puts ("nextafter+ did not underflow");
00178       ++result;
00179     }
00180   feclearexcept (FE_ALL_EXCEPT);
00181   if (nextafter (dm, di) != 0.0)
00182     {
00183       puts ("nextafter+ failed");
00184       ++result;
00185     }
00186   if (fetestexcept (FE_UNDERFLOW) == 0)
00187     {
00188       puts ("nextafter+ did not underflow");
00189       ++result;
00190     }
00191   feclearexcept (FE_ALL_EXCEPT);
00192   dm = nextafter (copysign (zero, -1.0), -inf);
00193   if (dm > 0.0 || dm <= -DBL_MIN)
00194     {
00195       puts ("nextafter- failed");
00196       ++result;
00197     }
00198   if (fetestexcept (FE_UNDERFLOW) == 0)
00199     {
00200       puts ("nextafter- did not underflow");
00201       ++result;
00202     }
00203   feclearexcept (FE_ALL_EXCEPT);
00204   if (nextafter (dm, -di) != 0.0)
00205     {
00206       puts ("nextafter- failed");
00207       ++result;
00208     }
00209   if (fetestexcept (FE_UNDERFLOW) == 0)
00210     {
00211       puts ("nextafter- did not underflow");
00212       ++result;
00213     }
00214 
00215 #ifndef NO_LONG_DOUBLE
00216   long double li = INFINITY;
00217   long double lm = LDBL_MAX;
00218   feclearexcept (FE_ALL_EXCEPT);
00219   if (nextafterl (lm, li) != li)
00220     {
00221       puts ("nextafterl+ failed");
00222       ++result;
00223     }
00224   if (fetestexcept (FE_OVERFLOW) == 0)
00225     {
00226       puts ("nextafterl+ did not overflow");
00227       ++result;
00228     }
00229   feclearexcept (FE_ALL_EXCEPT);
00230   if (nextafterl (-lm, -li) != -li)
00231     {
00232       puts ("nextafterl failed");
00233       ++result;
00234     }
00235   if (fetestexcept (FE_OVERFLOW) == 0)
00236     {
00237       puts ("nextafterl- did not overflow");
00238       ++result;
00239     }
00240 
00241   li = 0;
00242   lm = LDBL_MIN;
00243   feclearexcept (FE_ALL_EXCEPT);
00244   li = nextafterl (lm, li);
00245   if (li < 0 || li >= LDBL_MIN)
00246     {
00247       puts ("nextafterl+ failed");
00248       ++result;
00249     }
00250   if (fetestexcept (FE_UNDERFLOW) == 0)
00251     {
00252       puts ("nextafterl+ did not underflow");
00253       ++result;
00254     }
00255   li = 0;
00256   feclearexcept (FE_ALL_EXCEPT);
00257   li = nextafterl (-lm, -li);
00258   if (li > 0 || li <= -LDBL_MIN)
00259     {
00260       puts ("nextafterl- failed");
00261       ++result;
00262     }
00263   if (fetestexcept (FE_UNDERFLOW) == 0)
00264     {
00265       puts ("nextafterl- did not underflow");
00266       ++result;
00267     }
00268   li = -INFINITY;
00269   feclearexcept (FE_ALL_EXCEPT);
00270   lm = nextafterl (zero, inf);
00271   if (lm < 0.0 || lm >= LDBL_MIN)
00272     {
00273       puts ("nextafterl+ failed");
00274       ++result;
00275     }
00276   if (fetestexcept (FE_UNDERFLOW) == 0)
00277     {
00278       puts ("nextafterl+ did not underflow");
00279       ++result;
00280     }
00281   feclearexcept (FE_ALL_EXCEPT);
00282   if (nextafterl (lm, li) != 0.0)
00283     {
00284       puts ("nextafterl+ failed");
00285       ++result;
00286     }
00287   if (fetestexcept (FE_UNDERFLOW) == 0)
00288     {
00289       puts ("nextafterl+ did not underflow");
00290       ++result;
00291     }
00292   feclearexcept (FE_ALL_EXCEPT);
00293   lm = nextafterl (copysign (zero, -1.0), -inf);
00294   if (lm > 0.0 || lm <= -LDBL_MIN)
00295     {
00296       puts ("nextafterl- failed");
00297       ++result;
00298     }
00299   if (fetestexcept (FE_UNDERFLOW) == 0)
00300     {
00301       puts ("nextafterl- did not underflow");
00302       ++result;
00303     }
00304   feclearexcept (FE_ALL_EXCEPT);
00305   if (nextafterl (lm, -li) != 0.0)
00306     {
00307       puts ("nextafterl- failed");
00308       ++result;
00309     }
00310   if (fetestexcept (FE_UNDERFLOW) == 0)
00311     {
00312       puts ("nextafterl- did not underflow");
00313       ++result;
00314     }
00315 #endif
00316 
00317   return result;
00318 }