Back to index

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