Back to index

glibc  2.9
test-misc.c
Go to the documentation of this file.
00001 /* Miscellaneous tests which don't fit anywhere else.
00002    Copyright (C) 2000, 2001, 2004, 2005, 2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <fenv.h>
00021 #include <float.h>
00022 #include <ieee754.h>
00023 #include <math.h>
00024 #include <stdio.h>
00025 #include <string.h>
00026 
00027 
00028 int
00029 main (void)
00030 {
00031   int result = 0;
00032 
00033 #ifndef NO_LONG_DOUBLE
00034   {
00035     long double x = 0x100000001ll + (long double) 0.5;
00036     long double q;
00037     long double r;
00038 
00039     r = modfl (x, &q);
00040     if (q != (long double) 0x100000001ll || r != 0.5)
00041       {
00042        printf ("modfl (%Lg, ...) failed\n", x);
00043        result = 1;
00044       }
00045   }
00046 
00047   {
00048     long double x;
00049     long double m;
00050     long double r;
00051     int e;
00052     int i;
00053 
00054 # if LDBL_MANT_DIG == 64
00055     m = 0xf.fffffffffffffffp-4L;
00056 # elif LDBL_MANT_DIG == 106
00057     /* This has to match the mantissa of LDBL_MAX which actually does have a
00058        missing bit in the middle.  */
00059     m = 0x1.fffffffffffff7ffffffffffff8p-1L;
00060 # elif LDBL_MANT_DIG == 113
00061     m = 0x1.ffffffffffffffffffffffffffffp-1L;
00062 # else
00063 #  error "Please adjust"
00064 # endif
00065 
00066     for (i = LDBL_MAX_EXP, x = LDBL_MAX; i >= LDBL_MIN_EXP; --i, x /= 2.0L)
00067       {
00068        printf ("2^%d: ", i);
00069 
00070        r = frexpl (x, &e);
00071        if (r != m)
00072          {
00073            printf ("mantissa incorrect: %.20La\n", r);
00074            result = 1;
00075            continue;
00076          }
00077        if (e != i)
00078          {
00079            printf ("exponent wrong %d (%.20Lg)\n", e, x);
00080            result = 1;
00081            continue;
00082          }
00083        puts ("ok");
00084       }
00085 
00086     for (i = LDBL_MIN_EXP, x = LDBL_MIN; i >= LDBL_MIN_EXP - LDBL_MANT_DIG + 1;
00087         --i, x /= 2.0L)
00088       {
00089         printf ("2^%d: ", i);
00090 
00091         r = frexpl (x, &e);
00092         if (r != 0.5L)
00093           {
00094             printf ("mantissa incorrect: %.20La\n", r);
00095             result = 1;
00096             continue;
00097           }
00098         if (e != i)
00099           {
00100             printf ("exponent wrong %d (%.20Lg)\n", e, x);
00101             result = 1;
00102             continue;
00103           }
00104         puts ("ok");
00105       }
00106 
00107   }
00108 
00109 # if 0
00110   {
00111     int e;
00112     long double r = frexpl (LDBL_MIN * LDBL_EPSILON, &e);
00113 
00114     if (r != 0.5)
00115       {
00116        printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): mantissa wrong: %Lg\n",
00117               r);
00118        result = 1;
00119       }
00120     else if (e != -16444)
00121       {
00122        printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): exponent wrong: %d\n",
00123               e);
00124        result = 1;
00125       }
00126   }
00127 # endif
00128 #endif
00129 
00130   {
00131     double x = 0x100000001ll + (double) 0.5;
00132     double q;
00133     double r;
00134 
00135     r = modf (x, &q);
00136     if (q != (double) 0x100000001ll || r != 0.5)
00137       {
00138        printf ("modf (%g, ...) failed\n", x);
00139        result = 1;
00140       }
00141   }
00142 
00143   {
00144     union ieee754_float v1;
00145     union ieee754_float v2;
00146     float f;
00147 
00148     v1.f = f = FLT_MIN;
00149     if (fpclassify (f) != FP_NORMAL)
00150       {
00151        printf ("fpclassify (FLT_MIN) failed: %d\n", fpclassify (f));
00152        result = 1;
00153       }
00154     f = nextafterf (f, FLT_MIN / 2.0f);
00155     if (fpclassify (f) != FP_SUBNORMAL)
00156       {
00157        printf ("fpclassify (FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
00158        result = 1;
00159       }
00160     v2.f = f = nextafterf (f, FLT_MIN);
00161     if (fpclassify (f) != FP_NORMAL)
00162       {
00163        printf ("fpclassify (FLT_MIN-epsilon+epsilon) failed: %d\n",
00164               fpclassify (f));
00165        result = 1;
00166       }
00167 
00168     if (v1.ieee.mantissa != v2.ieee.mantissa)
00169       {
00170        printf ("FLT_MIN: mantissa differs: %8x vs %8x\n",
00171               v1.ieee.mantissa, v2.ieee.mantissa);
00172        result = 1;
00173       }
00174     if (v1.ieee.exponent != v2.ieee.exponent)
00175       {
00176        printf ("FLT_MIN: exponent differs: %4x vs %4x\n",
00177               v1.ieee.exponent, v2.ieee.exponent);
00178        result = 1;
00179       }
00180     if (v1.ieee.negative != v2.ieee.negative)
00181       {
00182        printf ("FLT_MIN: negative differs: %d vs %d\n",
00183               v1.ieee.negative, v2.ieee.negative);
00184        result = 1;
00185       }
00186 
00187     v1.f = f = -FLT_MIN;
00188     if (fpclassify (f) != FP_NORMAL)
00189       {
00190        printf ("fpclassify (-FLT_MIN) failed: %d\n", fpclassify (f));
00191        result = 1;
00192       }
00193     f = nextafterf (f, -FLT_MIN / 2.0f);
00194     if (fpclassify (f) != FP_SUBNORMAL)
00195       {
00196        printf ("fpclassify (-FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
00197        result = 1;
00198       }
00199     v2.f = f = nextafterf (f, -FLT_MIN);
00200     if (fpclassify (f) != FP_NORMAL)
00201       {
00202        printf ("fpclassify (-FLT_MIN-epsilon+epsilon) failed: %d\n",
00203               fpclassify (f));
00204        result = 1;
00205       }
00206 
00207     if (v1.ieee.mantissa != v2.ieee.mantissa)
00208       {
00209        printf ("-FLT_MIN: mantissa differs: %8x vs %8x\n",
00210               v1.ieee.mantissa, v2.ieee.mantissa);
00211        result = 1;
00212       }
00213     if (v1.ieee.exponent != v2.ieee.exponent)
00214       {
00215        printf ("-FLT_MIN: exponent differs: %4x vs %4x\n",
00216               v1.ieee.exponent, v2.ieee.exponent);
00217        result = 1;
00218       }
00219     if (v1.ieee.negative != v2.ieee.negative)
00220       {
00221        printf ("-FLT_MIN: negative differs: %d vs %d\n",
00222               v1.ieee.negative, v2.ieee.negative);
00223        result = 1;
00224       }
00225 
00226     f = FLT_MAX;
00227     if (fpclassify (f) != FP_NORMAL)
00228       {
00229        printf ("fpclassify (FLT_MAX) failed: %d\n", fpclassify (f));
00230        result = 1;
00231       }
00232     f = nextafterf (f, INFINITY);
00233     if (fpclassify (f) != FP_INFINITE)
00234       {
00235        printf ("fpclassify (FLT_MAX+epsilon) failed: %d\n", fpclassify (f));
00236        result = 1;
00237       }
00238 
00239     f = -FLT_MAX;
00240     if (fpclassify (f) != FP_NORMAL)
00241       {
00242        printf ("fpclassify (-FLT_MAX) failed: %d\n", fpclassify (f));
00243        result = 1;
00244       }
00245     f = nextafterf (f, -INFINITY);
00246     if (fpclassify (f) != FP_INFINITE)
00247       {
00248        printf ("fpclassify (-FLT_MAX-epsilon) failed: %d\n", fpclassify (f));
00249        result = 1;
00250       }
00251 
00252     v1.f = f = 0.0625;
00253     f = nextafterf (f, 0.0);
00254     v2.f = f = nextafterf (f, 1.0);
00255 
00256     if (v1.ieee.mantissa != v2.ieee.mantissa)
00257       {
00258        printf ("0.0625f down: mantissa differs: %8x vs %8x\n",
00259               v1.ieee.mantissa, v2.ieee.mantissa);
00260        result = 1;
00261       }
00262     if (v1.ieee.exponent != v2.ieee.exponent)
00263       {
00264        printf ("0.0625f down: exponent differs: %4x vs %4x\n",
00265               v1.ieee.exponent, v2.ieee.exponent);
00266        result = 1;
00267       }
00268     if (v1.ieee.negative != v2.ieee.negative)
00269       {
00270        printf ("0.0625f down: negative differs: %d vs %d\n",
00271               v1.ieee.negative, v2.ieee.negative);
00272        result = 1;
00273       }
00274 
00275     v1.f = f = 0.0625;
00276     f = nextafterf (f, 1.0);
00277     v2.f = f = nextafterf (f, 0.0);
00278 
00279     if (v1.ieee.mantissa != v2.ieee.mantissa)
00280       {
00281        printf ("0.0625f up: mantissa differs: %8x vs %8x\n",
00282               v1.ieee.mantissa, v2.ieee.mantissa);
00283        result = 1;
00284       }
00285     if (v1.ieee.exponent != v2.ieee.exponent)
00286       {
00287        printf ("0.0625f up: exponent differs: %4x vs %4x\n",
00288               v1.ieee.exponent, v2.ieee.exponent);
00289        result = 1;
00290       }
00291     if (v1.ieee.negative != v2.ieee.negative)
00292       {
00293        printf ("0.0625f up: negative differs: %d vs %d\n",
00294               v1.ieee.negative, v2.ieee.negative);
00295        result = 1;
00296       }
00297 
00298     v1.f = f = -0.0625;
00299     f = nextafterf (f, 0.0);
00300     v2.f = f = nextafterf (f, -1.0);
00301 
00302     if (v1.ieee.mantissa != v2.ieee.mantissa)
00303       {
00304        printf ("-0.0625f up: mantissa differs: %8x vs %8x\n",
00305               v1.ieee.mantissa, v2.ieee.mantissa);
00306        result = 1;
00307       }
00308     if (v1.ieee.exponent != v2.ieee.exponent)
00309       {
00310        printf ("-0.0625f up: exponent differs: %4x vs %4x\n",
00311               v1.ieee.exponent, v2.ieee.exponent);
00312        result = 1;
00313       }
00314     if (v1.ieee.negative != v2.ieee.negative)
00315       {
00316        printf ("-0.0625f up: negative differs: %d vs %d\n",
00317               v1.ieee.negative, v2.ieee.negative);
00318        result = 1;
00319       }
00320 
00321     v1.f = f = -0.0625;
00322     f = nextafterf (f, -1.0);
00323     v2.f = f = nextafterf (f, 0.0);
00324 
00325     if (v1.ieee.mantissa != v2.ieee.mantissa)
00326       {
00327        printf ("-0.0625f down: mantissa differs: %8x vs %8x\n",
00328               v1.ieee.mantissa, v2.ieee.mantissa);
00329        result = 1;
00330       }
00331     if (v1.ieee.exponent != v2.ieee.exponent)
00332       {
00333        printf ("-0.0625f down: exponent differs: %4x vs %4x\n",
00334               v1.ieee.exponent, v2.ieee.exponent);
00335        result = 1;
00336       }
00337     if (v1.ieee.negative != v2.ieee.negative)
00338       {
00339        printf ("-0.0625f down: negative differs: %d vs %d\n",
00340               v1.ieee.negative, v2.ieee.negative);
00341        result = 1;
00342       }
00343 
00344     v1.f = f = 0.0f;
00345     f = nextafterf (f, 1.0);
00346     v2.f = nextafterf (f, -1.0);
00347 
00348     if (v1.ieee.mantissa != v2.ieee.mantissa)
00349       {
00350        printf ("0.0f up: mantissa differs: %8x vs %8x\n",
00351               v1.ieee.mantissa, v2.ieee.mantissa);
00352        result = 1;
00353       }
00354     if (v1.ieee.exponent != v2.ieee.exponent)
00355       {
00356        printf ("0.0f up: exponent differs: %4x vs %4x\n",
00357               v1.ieee.exponent, v2.ieee.exponent);
00358        result = 1;
00359       }
00360     if (0 != v2.ieee.negative)
00361       {
00362        printf ("0.0f up: negative differs: 0 vs %d\n",
00363               v2.ieee.negative);
00364        result = 1;
00365       }
00366 
00367     v1.f = f = 0.0f;
00368     f = nextafterf (f, -1.0);
00369     v2.f = nextafterf (f, 1.0);
00370 
00371     if (v1.ieee.mantissa != v2.ieee.mantissa)
00372       {
00373        printf ("0.0f down: mantissa differs: %8x vs %8x\n",
00374               v1.ieee.mantissa, v2.ieee.mantissa);
00375        result = 1;
00376       }
00377     if (v1.ieee.exponent != v2.ieee.exponent)
00378       {
00379        printf ("0.0f down: exponent differs: %4x vs %4x\n",
00380               v1.ieee.exponent, v2.ieee.exponent);
00381        result = 1;
00382       }
00383     if (1 != v2.ieee.negative)
00384       {
00385        printf ("0.0f down: negative differs: 1 vs %d\n",
00386               v2.ieee.negative);
00387        result = 1;
00388       }
00389 
00390     if (nextafterf (0.0f, INFINITY) != nextafterf (0.0f, 1.0f)
00391         || nextafterf (-0.0f, INFINITY) != nextafterf (-0.0f, 1.0f)
00392         || nextafterf (0.0f, -INFINITY) != nextafterf (0.0f, -1.0f)
00393         || nextafterf (-0.0f, -INFINITY) != nextafterf (-0.0f, -1.0f))
00394       {
00395        printf ("nextafterf (+-0, +-Inf) != nextafterf (+-0, +-1)\n");
00396        result = 1;
00397       }
00398 
00399     if (nexttowardf (0.0f, INFINITY) != nexttowardf (0.0f, 1.0f)
00400         || nexttowardf (-0.0f, INFINITY) != nexttowardf (-0.0f, 1.0f)
00401         || nexttowardf (0.0f, -INFINITY) != nexttowardf (0.0f, -1.0f)
00402         || nexttowardf (-0.0f, -INFINITY) != nexttowardf (-0.0f, -1.0f))
00403       {
00404        printf ("nexttowardf (+-0, +-Inf) != nexttowardf (+-0, +-1)\n");
00405        result = 1;
00406       }
00407   }
00408 
00409   {
00410     union ieee754_double v1;
00411     union ieee754_double v2;
00412     double d;
00413 
00414     v1.d = d = DBL_MIN;
00415     if (fpclassify (d) != FP_NORMAL)
00416       {
00417        printf ("fpclassify (DBL_MIN) failed: %d\n", fpclassify (d));
00418        result = 1;
00419       }
00420     d = nextafter (d, DBL_MIN / 2.0);
00421     if (fpclassify (d) != FP_SUBNORMAL)
00422       {
00423        printf ("fpclassify (DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
00424        result = 1;
00425       }
00426     v2.d = d = nextafter (d, DBL_MIN);
00427     if (fpclassify (d) != FP_NORMAL)
00428       {
00429        printf ("fpclassify (DBL_MIN-epsilon+epsilon) failed: %d\n",
00430               fpclassify (d));
00431        result = 1;
00432       }
00433 
00434     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00435       {
00436        printf ("DBL_MIN: mantissa0 differs: %8x vs %8x\n",
00437               v1.ieee.mantissa0, v2.ieee.mantissa0);
00438        result = 1;
00439       }
00440     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00441       {
00442        printf ("DBL_MIN: mantissa1 differs: %8x vs %8x\n",
00443               v1.ieee.mantissa1, v2.ieee.mantissa1);
00444        result = 1;
00445       }
00446     if (v1.ieee.exponent != v2.ieee.exponent)
00447       {
00448        printf ("DBL_MIN: exponent differs: %4x vs %4x\n",
00449               v1.ieee.exponent, v2.ieee.exponent);
00450        result = 1;
00451       }
00452     if (v1.ieee.negative != v2.ieee.negative)
00453       {
00454        printf ("DBL_MIN: negative differs: %d vs %d\n",
00455               v1.ieee.negative, v2.ieee.negative);
00456        result = 1;
00457       }
00458 
00459     v1.d = d = -DBL_MIN;
00460     if (fpclassify (d) != FP_NORMAL)
00461       {
00462        printf ("fpclassify (-DBL_MIN) failed: %d\n", fpclassify (d));
00463        result = 1;
00464       }
00465     d = nextafter (d, -DBL_MIN / 2.0);
00466     if (fpclassify (d) != FP_SUBNORMAL)
00467       {
00468        printf ("fpclassify (-DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
00469        result = 1;
00470       }
00471     v2.d = d = nextafter (d, -DBL_MIN);
00472     if (fpclassify (d) != FP_NORMAL)
00473       {
00474        printf ("fpclassify (-DBL_MIN-epsilon+epsilon) failed: %d\n",
00475               fpclassify (d));
00476        result = 1;
00477       }
00478 
00479     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00480       {
00481        printf ("-DBL_MIN: mantissa0 differs: %8x vs %8x\n",
00482               v1.ieee.mantissa0, v2.ieee.mantissa0);
00483        result = 1;
00484       }
00485     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00486       {
00487        printf ("-DBL_MIN: mantissa1 differs: %8x vs %8x\n",
00488               v1.ieee.mantissa1, v2.ieee.mantissa1);
00489        result = 1;
00490       }
00491     if (v1.ieee.exponent != v2.ieee.exponent)
00492       {
00493        printf ("-DBL_MIN: exponent differs: %4x vs %4x\n",
00494               v1.ieee.exponent, v2.ieee.exponent);
00495        result = 1;
00496       }
00497     if (v1.ieee.negative != v2.ieee.negative)
00498       {
00499        printf ("-DBL_MIN: negative differs: %d vs %d\n",
00500               v1.ieee.negative, v2.ieee.negative);
00501        result = 1;
00502       }
00503 
00504     d = DBL_MAX;
00505     if (fpclassify (d) != FP_NORMAL)
00506       {
00507        printf ("fpclassify (DBL_MAX) failed: %d\n", fpclassify (d));
00508        result = 1;
00509       }
00510     d = nextafter (d, INFINITY);
00511     if (fpclassify (d) != FP_INFINITE)
00512       {
00513        printf ("fpclassify (DBL_MAX+epsilon) failed: %d\n", fpclassify (d));
00514        result = 1;
00515       }
00516 
00517     d = -DBL_MAX;
00518     if (fpclassify (d) != FP_NORMAL)
00519       {
00520        printf ("fpclassify (-DBL_MAX) failed: %d\n", fpclassify (d));
00521        result = 1;
00522       }
00523     d = nextafter (d, -INFINITY);
00524     if (fpclassify (d) != FP_INFINITE)
00525       {
00526        printf ("fpclassify (-DBL_MAX-epsilon) failed: %d\n", fpclassify (d));
00527        result = 1;
00528       }
00529 
00530     v1.d = d = 0.0625;
00531     d = nextafter (d, 0.0);
00532     v2.d = d = nextafter (d, 1.0);
00533 
00534     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00535       {
00536        printf ("0.0625 down: mantissa0 differs: %8x vs %8x\n",
00537               v1.ieee.mantissa0, v2.ieee.mantissa0);
00538        result = 1;
00539       }
00540     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00541       {
00542        printf ("0.0625 down: mantissa1 differs: %8x vs %8x\n",
00543               v1.ieee.mantissa1, v2.ieee.mantissa1);
00544        result = 1;
00545       }
00546     if (v1.ieee.exponent != v2.ieee.exponent)
00547       {
00548        printf ("0.0625 down: exponent differs: %4x vs %4x\n",
00549               v1.ieee.exponent, v2.ieee.exponent);
00550        result = 1;
00551       }
00552     if (v1.ieee.negative != v2.ieee.negative)
00553       {
00554        printf ("0.0625 down: negative differs: %d vs %d\n",
00555               v1.ieee.negative, v2.ieee.negative);
00556        result = 1;
00557       }
00558 
00559     v1.d = d = 0.0625;
00560     d = nextafter (d, 1.0);
00561     v2.d = d = nextafter (d, 0.0);
00562 
00563     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00564       {
00565        printf ("0.0625 up: mantissa0 differs: %8x vs %8x\n",
00566               v1.ieee.mantissa0, v2.ieee.mantissa0);
00567        result = 1;
00568       }
00569     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00570       {
00571        printf ("0.0625 up: mantissa1 differs: %8x vs %8x\n",
00572               v1.ieee.mantissa1, v2.ieee.mantissa1);
00573        result = 1;
00574       }
00575     if (v1.ieee.exponent != v2.ieee.exponent)
00576       {
00577        printf ("0.0625 up: exponent differs: %4x vs %4x\n",
00578               v1.ieee.exponent, v2.ieee.exponent);
00579        result = 1;
00580       }
00581     if (v1.ieee.negative != v2.ieee.negative)
00582       {
00583        printf ("0.0625 up: negative differs: %d vs %d\n",
00584               v1.ieee.negative, v2.ieee.negative);
00585        result = 1;
00586       }
00587 
00588     v1.d = d = -0.0625;
00589     d = nextafter (d, 0.0);
00590     v2.d = d = nextafter (d, -1.0);
00591 
00592     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00593       {
00594        printf ("-0.0625 up: mantissa0 differs: %8x vs %8x\n",
00595               v1.ieee.mantissa0, v2.ieee.mantissa0);
00596        result = 1;
00597       }
00598     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00599       {
00600        printf ("-0.0625 up: mantissa1 differs: %8x vs %8x\n",
00601               v1.ieee.mantissa1, v2.ieee.mantissa1);
00602        result = 1;
00603       }
00604     if (v1.ieee.exponent != v2.ieee.exponent)
00605       {
00606        printf ("-0.0625 up: exponent differs: %4x vs %4x\n",
00607               v1.ieee.exponent, v2.ieee.exponent);
00608        result = 1;
00609       }
00610     if (v1.ieee.negative != v2.ieee.negative)
00611       {
00612        printf ("-0.0625 up: negative differs: %d vs %d\n",
00613               v1.ieee.negative, v2.ieee.negative);
00614        result = 1;
00615       }
00616 
00617     v1.d = d = -0.0625;
00618     d = nextafter (d, -1.0);
00619     v2.d = d = nextafter (d, 0.0);
00620 
00621     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00622       {
00623        printf ("-0.0625 down: mantissa0 differs: %8x vs %8x\n",
00624               v1.ieee.mantissa0, v2.ieee.mantissa0);
00625        result = 1;
00626       }
00627     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00628       {
00629        printf ("-0.0625 down: mantissa1 differs: %8x vs %8x\n",
00630               v1.ieee.mantissa1, v2.ieee.mantissa1);
00631        result = 1;
00632       }
00633     if (v1.ieee.exponent != v2.ieee.exponent)
00634       {
00635        printf ("-0.0625 down: exponent differs: %4x vs %4x\n",
00636               v1.ieee.exponent, v2.ieee.exponent);
00637        result = 1;
00638       }
00639     if (v1.ieee.negative != v2.ieee.negative)
00640       {
00641        printf ("-0.0625 down: negative differs: %d vs %d\n",
00642               v1.ieee.negative, v2.ieee.negative);
00643        result = 1;
00644       }
00645 
00646     v1.d = d = 0.0;
00647     d = nextafter (d, 1.0);
00648     v2.d = nextafter (d, -1.0);
00649 
00650     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00651       {
00652        printf ("0.0 up: mantissa0 differs: %8x vs %8x\n",
00653               v1.ieee.mantissa0, v2.ieee.mantissa0);
00654        result = 1;
00655       }
00656     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00657       {
00658        printf ("0.0 up: mantissa1 differs: %8x vs %8x\n",
00659               v1.ieee.mantissa1, v2.ieee.mantissa1);
00660        result = 1;
00661       }
00662     if (v1.ieee.exponent != v2.ieee.exponent)
00663       {
00664        printf ("0.0 up: exponent differs: %4x vs %4x\n",
00665               v1.ieee.exponent, v2.ieee.exponent);
00666        result = 1;
00667       }
00668     if (0 != v2.ieee.negative)
00669       {
00670        printf ("0.0 up: negative differs: 0 vs %d\n",
00671               v2.ieee.negative);
00672        result = 1;
00673       }
00674 
00675     v1.d = d = 0.0;
00676     d = nextafter (d, -1.0);
00677     v2.d = nextafter (d, 1.0);
00678 
00679     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00680       {
00681        printf ("0.0 down: mantissa0 differs: %8x vs %8x\n",
00682               v1.ieee.mantissa0, v2.ieee.mantissa0);
00683        result = 1;
00684       }
00685     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00686       {
00687        printf ("0.0 down: mantissa1 differs: %8x vs %8x\n",
00688               v1.ieee.mantissa1, v2.ieee.mantissa1);
00689        result = 1;
00690       }
00691     if (v1.ieee.exponent != v2.ieee.exponent)
00692       {
00693        printf ("0.0 down: exponent differs: %4x vs %4x\n",
00694               v1.ieee.exponent, v2.ieee.exponent);
00695        result = 1;
00696       }
00697     if (1 != v2.ieee.negative)
00698       {
00699        printf ("0.0 down: negative differs: 1 vs %d\n",
00700               v2.ieee.negative);
00701        result = 1;
00702       }
00703 
00704     if (nextafter (0.0, INFINITY) != nextafter (0.0, 1.0)
00705         || nextafter (-0.0, INFINITY) != nextafter (-0.0, 1.0)
00706         || nextafter (0.0, -INFINITY) != nextafter (0.0, -1.0)
00707         || nextafter (-0.0, -INFINITY) != nextafter (-0.0, -1.0))
00708       {
00709        printf ("nextafter (+-0, +-Inf) != nextafter (+-0, +-1)\n");
00710        result = 1;
00711       }
00712 
00713     if (nexttoward (0.0, INFINITY) != nexttoward (0.0, 1.0)
00714         || nexttoward (-0.0, INFINITY) != nexttoward (-0.0, 1.0)
00715         || nexttoward (0.0, -INFINITY) != nexttoward (0.0, -1.0)
00716         || nexttoward (-0.0, -INFINITY) != nexttoward (-0.0, -1.0))
00717       {
00718        printf ("nexttoward (+-0, +-Inf) != nexttoward (+-0, +-1)\n");
00719        result = 1;
00720       }
00721   }
00722 
00723 #ifndef NO_LONG_DOUBLE
00724   {
00725     union ieee854_long_double v1;
00726     union ieee854_long_double v2;
00727     long double ld;
00728 
00729     v1.d = ld = LDBL_MIN;
00730     if (fpclassify (ld) != FP_NORMAL)
00731       {
00732        printf ("fpclassify (LDBL_MIN) failed: %d\n", fpclassify (ld));
00733        result = 1;
00734       }
00735     ld = nextafterl (ld, LDBL_MIN / 2.0);
00736     if (fpclassify (ld) != FP_SUBNORMAL)
00737       {
00738        printf ("fpclassify (LDBL_MIN-epsilon) failed: %d (%La)\n",
00739               fpclassify (ld), ld);
00740        result = 1;
00741       }
00742     v2.d = ld = nextafterl (ld, LDBL_MIN);
00743     if (fpclassify (ld) != FP_NORMAL)
00744       {
00745        printf ("fpclassify (LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
00746               fpclassify (ld), ld);
00747        result = 1;
00748       }
00749 
00750     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00751       {
00752        printf ("LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
00753               v1.ieee.mantissa0, v2.ieee.mantissa0);
00754        result = 1;
00755       }
00756     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00757       {
00758        printf ("LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
00759               v1.ieee.mantissa1, v2.ieee.mantissa1);
00760        result = 1;
00761       }
00762     if (v1.ieee.exponent != v2.ieee.exponent)
00763       {
00764        printf ("LDBL_MIN: exponent differs: %4x vs %4x\n",
00765               v1.ieee.exponent, v2.ieee.exponent);
00766        result = 1;
00767       }
00768     if (v1.ieee.negative != v2.ieee.negative)
00769       {
00770        printf ("LDBL_MIN: negative differs: %d vs %d\n",
00771               v1.ieee.negative, v2.ieee.negative);
00772        result = 1;
00773       }
00774 
00775     v1.d = ld = -LDBL_MIN;
00776     if (fpclassify (ld) != FP_NORMAL)
00777       {
00778        printf ("fpclassify (-LDBL_MIN) failed: %d\n", fpclassify (ld));
00779        result = 1;
00780       }
00781     ld = nextafterl (ld, -LDBL_MIN / 2.0);
00782     if (fpclassify (ld) != FP_SUBNORMAL)
00783       {
00784        printf ("fpclassify (-LDBL_MIN-epsilon) failed: %d (%La)\n",
00785               fpclassify (ld), ld);
00786        result = 1;
00787       }
00788     v2.d = ld = nextafterl (ld, -LDBL_MIN);
00789     if (fpclassify (ld) != FP_NORMAL)
00790       {
00791        printf ("fpclassify (-LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
00792               fpclassify (ld), ld);
00793        result = 1;
00794       }
00795 
00796     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00797       {
00798        printf ("-LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
00799               v1.ieee.mantissa0, v2.ieee.mantissa0);
00800        result = 1;
00801       }
00802     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00803       {
00804        printf ("-LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
00805               v1.ieee.mantissa1, v2.ieee.mantissa1);
00806        result = 1;
00807       }
00808     if (v1.ieee.exponent != v2.ieee.exponent)
00809       {
00810        printf ("-LDBL_MIN: exponent differs: %4x vs %4x\n",
00811               v1.ieee.exponent, v2.ieee.exponent);
00812        result = 1;
00813       }
00814     if (v1.ieee.negative != v2.ieee.negative)
00815       {
00816        printf ("-LDBL_MIN: negative differs: %d vs %d\n",
00817               v1.ieee.negative, v2.ieee.negative);
00818        result = 1;
00819       }
00820 
00821     ld = LDBL_MAX;
00822     if (fpclassify (ld) != FP_NORMAL)
00823       {
00824        printf ("fpclassify (LDBL_MAX) failed: %d\n", fpclassify (ld));
00825        result = 1;
00826       }
00827     ld = nextafterl (ld, INFINITY);
00828     if (fpclassify (ld) != FP_INFINITE)
00829       {
00830        printf ("fpclassify (LDBL_MAX+epsilon) failed: %d\n", fpclassify (ld));
00831        result = 1;
00832       }
00833 
00834     ld = -LDBL_MAX;
00835     if (fpclassify (ld) != FP_NORMAL)
00836       {
00837        printf ("fpclassify (-LDBL_MAX) failed: %d\n", fpclassify (ld));
00838        result = 1;
00839       }
00840     ld = nextafterl (ld, -INFINITY);
00841     if (fpclassify (ld) != FP_INFINITE)
00842       {
00843        printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d\n",
00844               fpclassify (ld));
00845        result = 1;
00846       }
00847 
00848     v1.d = ld = 0.0625;
00849     ld = nextafterl (ld, 0.0);
00850     v2.d = ld = nextafterl (ld, 1.0);
00851 
00852     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00853       {
00854        printf ("0.0625L down: mantissa0 differs: %8x vs %8x\n",
00855               v1.ieee.mantissa0, v2.ieee.mantissa0);
00856        result = 1;
00857       }
00858     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00859       {
00860        printf ("0.0625L down: mantissa1 differs: %8x vs %8x\n",
00861               v1.ieee.mantissa1, v2.ieee.mantissa1);
00862        result = 1;
00863       }
00864     if (v1.ieee.exponent != v2.ieee.exponent)
00865       {
00866        printf ("0.0625L down: exponent differs: %4x vs %4x\n",
00867               v1.ieee.exponent, v2.ieee.exponent);
00868        result = 1;
00869       }
00870     if (v1.ieee.negative != v2.ieee.negative)
00871       {
00872        printf ("0.0625L down: negative differs: %d vs %d\n",
00873               v1.ieee.negative, v2.ieee.negative);
00874        result = 1;
00875       }
00876 
00877     v1.d = ld = 0.0625;
00878     ld = nextafterl (ld, 1.0);
00879     v2.d = ld = nextafterl (ld, 0.0);
00880 
00881     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00882       {
00883        printf ("0.0625L up: mantissa0 differs: %8x vs %8x\n",
00884               v1.ieee.mantissa0, v2.ieee.mantissa0);
00885        result = 1;
00886       }
00887     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00888       {
00889        printf ("0.0625L up: mantissa1 differs: %8x vs %8x\n",
00890               v1.ieee.mantissa1, v2.ieee.mantissa1);
00891        result = 1;
00892       }
00893     if (v1.ieee.exponent != v2.ieee.exponent)
00894       {
00895        printf ("0.0625L up: exponent differs: %4x vs %4x\n",
00896               v1.ieee.exponent, v2.ieee.exponent);
00897        result = 1;
00898       }
00899     if (v1.ieee.negative != v2.ieee.negative)
00900       {
00901        printf ("0.0625L up: negative differs: %d vs %d\n",
00902               v1.ieee.negative, v2.ieee.negative);
00903        result = 1;
00904       }
00905 
00906     v1.d = ld = -0.0625;
00907     ld = nextafterl (ld, 0.0);
00908     v2.d = ld = nextafterl (ld, -1.0);
00909 
00910     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00911       {
00912        printf ("-0.0625L up: mantissa0 differs: %8x vs %8x\n",
00913               v1.ieee.mantissa0, v2.ieee.mantissa0);
00914        result = 1;
00915       }
00916     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00917       {
00918        printf ("-0.0625L up: mantissa1 differs: %8x vs %8x\n",
00919               v1.ieee.mantissa1, v2.ieee.mantissa1);
00920        result = 1;
00921       }
00922     if (v1.ieee.exponent != v2.ieee.exponent)
00923       {
00924        printf ("-0.0625L up: exponent differs: %4x vs %4x\n",
00925               v1.ieee.exponent, v2.ieee.exponent);
00926        result = 1;
00927       }
00928     if (v1.ieee.negative != v2.ieee.negative)
00929       {
00930        printf ("-0.0625L up: negative differs: %d vs %d\n",
00931               v1.ieee.negative, v2.ieee.negative);
00932        result = 1;
00933       }
00934 
00935     v1.d = ld = -0.0625;
00936     ld = nextafterl (ld, -1.0);
00937     v2.d = ld = nextafterl (ld, 0.0);
00938 
00939     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00940       {
00941        printf ("-0.0625L down: mantissa0 differs: %8x vs %8x\n",
00942               v1.ieee.mantissa0, v2.ieee.mantissa0);
00943        result = 1;
00944       }
00945     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00946       {
00947        printf ("-0.0625L down: mantissa1 differs: %8x vs %8x\n",
00948               v1.ieee.mantissa1, v2.ieee.mantissa1);
00949        result = 1;
00950       }
00951     if (v1.ieee.exponent != v2.ieee.exponent)
00952       {
00953        printf ("-0.0625L down: exponent differs: %4x vs %4x\n",
00954               v1.ieee.exponent, v2.ieee.exponent);
00955        result = 1;
00956       }
00957     if (v1.ieee.negative != v2.ieee.negative)
00958       {
00959        printf ("-0.0625L down: negative differs: %d vs %d\n",
00960               v1.ieee.negative, v2.ieee.negative);
00961        result = 1;
00962       }
00963 
00964     v1.d = ld = 0.0;
00965     ld = nextafterl (ld, 1.0);
00966     v2.d = nextafterl (ld, -1.0);
00967 
00968     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00969       {
00970        printf ("0.0L up: mantissa0 differs: %8x vs %8x\n",
00971               v1.ieee.mantissa0, v2.ieee.mantissa0);
00972        result = 1;
00973       }
00974     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
00975       {
00976        printf ("0.0L up: mantissa1 differs: %8x vs %8x\n",
00977               v1.ieee.mantissa1, v2.ieee.mantissa1);
00978        result = 1;
00979       }
00980     if (v1.ieee.exponent != v2.ieee.exponent)
00981       {
00982        printf ("0.0L up: exponent differs: %4x vs %4x\n",
00983               v1.ieee.exponent, v2.ieee.exponent);
00984        result = 1;
00985       }
00986     if (0 != v2.ieee.negative)
00987       {
00988        printf ("0.0L up: negative differs: 0 vs %d\n",
00989               v2.ieee.negative);
00990        result = 1;
00991       }
00992 
00993     v1.d = ld = 0.0;
00994     ld = nextafterl (ld, -1.0);
00995     v2.d = nextafterl (ld, 1.0);
00996 
00997     if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
00998       {
00999        printf ("0.0L down: mantissa0 differs: %8x vs %8x\n",
01000               v1.ieee.mantissa0, v2.ieee.mantissa0);
01001        result = 1;
01002       }
01003     if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
01004       {
01005        printf ("0.0L down: mantissa1 differs: %8x vs %8x\n",
01006               v1.ieee.mantissa1, v2.ieee.mantissa1);
01007        result = 1;
01008       }
01009     if (v1.ieee.exponent != v2.ieee.exponent)
01010       {
01011        printf ("0.0L down: exponent differs: %4x vs %4x\n",
01012               v1.ieee.exponent, v2.ieee.exponent);
01013        result = 1;
01014       }
01015     if (1 != v2.ieee.negative)
01016       {
01017        printf ("0.0L down: negative differs: 1 vs %d\n",
01018               v2.ieee.negative);
01019        result = 1;
01020       }
01021 
01022     if (nextafterl (0.0, INFINITY) != nextafterl (0.0, 1.0)
01023         || nextafterl (-0.0, INFINITY) != nextafterl (-0.0, 1.0)
01024         || nextafterl (0.0, -INFINITY) != nextafterl (0.0, -1.0)
01025         || nextafterl (-0.0, -INFINITY) != nextafterl (-0.0, -1.0))
01026       {
01027        printf ("nextafterl (+-0, +-Inf) != nextafterl (+-0, +-1)\n");
01028        result = 1;
01029       }
01030 
01031     if (nexttowardl (0.0L, INFINITY) != nexttowardl (0.0L, 1.0L)
01032         || nexttowardl (-0.0L, INFINITY) != nexttowardl (-0.0L, 1.0L)
01033         || nexttowardl (0.0L, -INFINITY) != nexttowardl (0.0L, -1.0L)
01034         || nexttowardl (-0.0L, -INFINITY) != nexttowardl (-0.0L, -1.0L))
01035       {
01036        printf ("nexttowardl (+-0, +-Inf) != nexttowardl (+-0, +-1)\n");
01037        result = 1;
01038       }
01039   }
01040 #endif
01041 
01042   if (! isnormal (FLT_MIN))
01043     {
01044       puts ("isnormal (FLT_MIN) failed");
01045       result = 1;
01046     }
01047   if (! isnormal (DBL_MIN))
01048     {
01049       puts ("isnormal (DBL_MIN) failed");
01050       result = 1;
01051     }
01052 #ifndef NO_LONG_DOUBLE
01053   if (! isnormal (LDBL_MIN))
01054     {
01055       puts ("isnormal (LDBL_MIN) failed");
01056       result = 1;
01057     }
01058 #endif
01059 
01060 #ifdef __i386__
01061   /* This is a test for the strange long doubles in x86 FPUs.  */
01062   {
01063     union
01064     {
01065       char b[10];
01066       long double d;
01067     } u =
01068       { .b = { 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0 } };
01069 
01070     if (fpclassify (u.d) != FP_NORMAL)
01071       {
01072        printf ("fpclassify (0x00008000000000000000) failed: %d (%Lg)\n",
01073               fpclassify (u.d), u.d);
01074        result = 1;
01075       }
01076   }
01077 
01078   /* Special NaNs in x86 long double.  Test for scalbl.  */
01079   {
01080     union
01081     {
01082       char b[10];
01083       long double d;
01084     } u =
01085       { .b = { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
01086     long double r;
01087 
01088     r = scalbl (u.d, 0.0);
01089     if (!isnan (r))
01090       {
01091        puts ("scalbl(NaN, 0) does not return NaN");
01092        result = 1;
01093       }
01094     else if (memcmp (&r, &u.d, sizeof (double)) != 0)
01095       {
01096        puts ("scalbl(NaN, 0) does not return the same NaN");
01097        result = 1;
01098       }
01099   }
01100 #endif
01101 
01102 #ifndef NO_LONG_DOUBLE
01103   {
01104     long double r;
01105 
01106     feclearexcept (FE_ALL_EXCEPT);
01107     r = scalbl (LDBL_MIN, 2147483647);
01108     if (! isinf (r))
01109       {
01110        puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
01111        result = 1;
01112       }
01113     else if (signbit (r) != 0)
01114       {
01115        puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
01116        result = 1;
01117       }
01118     else if (fetestexcept (FE_UNDERFLOW))
01119       {
01120        puts ("scalbl(NaN, 0) raises underflow exception");
01121        result = 1;
01122       }
01123 
01124     feclearexcept (FE_ALL_EXCEPT);
01125     r = scalbl (LDBL_MAX, -2147483647);
01126     if (r != 0.0)
01127       {
01128        puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
01129        result = 1;
01130       }
01131     else if (signbit (r) != 0)
01132       {
01133        puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
01134        result = 1;
01135       }
01136     else if (fetestexcept (FE_OVERFLOW))
01137       {
01138        puts ("scalbl(NaN, 0) raises overflow exception");
01139        result = 1;
01140       }
01141   }
01142 #endif
01143 
01144   /* The tests here are very similar to tests earlier in this file,
01145      the important difference is just that there are no intervening
01146      union variables that cause some GCC versions to hide possible
01147      bugs in nextafter* implementation.  */
01148   if (nextafterf (nextafterf (FLT_MIN, FLT_MIN / 2.0), FLT_MIN) != FLT_MIN)
01149     {
01150       puts ("nextafterf FLT_MIN test failed");
01151       result = 1;
01152     }
01153   if (nextafterf (nextafterf (-FLT_MIN, -FLT_MIN / 2.0), -FLT_MIN)
01154       != -FLT_MIN)
01155     {
01156       puts ("nextafterf -FLT_MIN test failed");
01157       result = 1;
01158     }
01159   if (nextafter (nextafter (DBL_MIN, DBL_MIN / 2.0), DBL_MIN) != DBL_MIN)
01160     {
01161       puts ("nextafter DBL_MIN test failed");
01162       result = 1;
01163     }
01164   if (nextafter (nextafter (-DBL_MIN, -DBL_MIN / 2.0), -DBL_MIN) != -DBL_MIN)
01165     {
01166       puts ("nextafter -DBL_MIN test failed");
01167       result = 1;
01168     }
01169 #ifndef NO_LONG_DOUBLE
01170   if (nextafterl (nextafterl (LDBL_MIN, LDBL_MIN / 2.0), LDBL_MIN)
01171       != LDBL_MIN)
01172     {
01173       puts ("nextafterl LDBL_MIN test failed");
01174       result = 1;
01175     }
01176   if (nextafterl (nextafterl (-LDBL_MIN, -LDBL_MIN / 2.0), -LDBL_MIN)
01177       != -LDBL_MIN)
01178     {
01179       puts ("nextafterl -LDBL_MIN test failed");
01180       result = 1;
01181     }
01182 #endif
01183 
01184   volatile float f1 = FLT_MAX;
01185   volatile float f2 = FLT_MAX / 2;
01186   (void) &f1;
01187   (void) &f2;
01188   feclearexcept (FE_ALL_EXCEPT);
01189   f2 += f1;
01190   int fe = fetestexcept (FE_ALL_EXCEPT);
01191   if (fe != (FE_OVERFLOW | FE_INEXACT))
01192     {
01193       printf ("float overflow test failed: %x\n", fe);
01194       result = 1;
01195     }
01196 
01197   volatile double d1 = DBL_MAX;
01198   volatile double d2 = DBL_MAX / 2;
01199   (void) &d1;
01200   (void) &d2;
01201   feclearexcept (FE_ALL_EXCEPT);
01202   d2 += d1;
01203   fe = fetestexcept (FE_ALL_EXCEPT);
01204   if (fe != (FE_OVERFLOW | FE_INEXACT))
01205     {
01206       printf ("double overflow test failed: %x\n", fe);
01207       result = 1;
01208     }
01209 
01210 #ifndef NO_LONG_DOUBLE
01211   volatile long double ld1 = LDBL_MAX;
01212   volatile long double ld2 = LDBL_MAX / 2;
01213   (void) &ld1;
01214   (void) &ld2;
01215   feclearexcept (FE_ALL_EXCEPT);
01216   ld2 += ld1;
01217   fe = fetestexcept (FE_ALL_EXCEPT);
01218   if (fe != (FE_OVERFLOW | FE_INEXACT))
01219     {
01220       printf ("long double overflow test failed: %x\n", fe);
01221       result = 1;
01222     }
01223 #endif
01224 
01225 #if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG == 113
01226   volatile long double ld3 = 0x1.0000000000010000000100000001p+1;
01227   volatile long double ld4 = 0x1.0000000000000000000000000001p+1;
01228   (void) &ld3;
01229   (void) &ld4;
01230   ld3 -= ld4;
01231   if (ld3 != 0x1.0p-47)
01232     {
01233       printf ("long double subtraction test failed %.28La\n", ld3);
01234       result = 1;
01235     }
01236 #endif
01237 
01238 /* Skip testing IBM long double format, for 2 reasons:
01239    1) it only supports FE_TONEAREST
01240    2) nextafter (0.0, 1.0) == nextafterl (0.0L, 1.0L), so
01241       nextafter (0.0, 1.0) / 16.0L will be 0.0L.  */
01242 #if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG >= DBL_MANT_DIG + 4 \
01243     && LDBL_MANT_DIG != 106
01244   int oldmode = fegetround ();
01245   int j;
01246   for (j = 0; j < 4; j++)
01247     {
01248       int mode;
01249       int i;
01250       int k = 0;
01251       const char *mstr;
01252       switch (j)
01253        {
01254 #ifdef FE_TONEAREST
01255        case 0:
01256          mode = FE_TONEAREST;
01257          mstr = "nearest";
01258          k = 8;
01259          break;
01260 #endif
01261 #ifdef FE_DOWNWARD
01262        case 1:
01263          mode = FE_DOWNWARD;
01264          mstr = "-inf";
01265          break;
01266 #endif
01267 #ifdef FE_UPWARD
01268        case 2:
01269          mode = FE_UPWARD;
01270          mstr = "+inf";
01271          k = 15;
01272          break;
01273 #endif
01274 #ifdef FE_TOWARDZERO
01275        case 3:
01276          mode = FE_TOWARDZERO;
01277          mstr = "0";
01278          break;
01279 #endif
01280        default:
01281          continue;
01282        }
01283 
01284       volatile long double ld5 = nextafter (0.0, 1.0) / 16.0L;
01285       volatile double d5;
01286       (void) &ld5;
01287       for (i = 0; i <= 32; i++)
01288        {
01289          if (fesetround (mode))
01290            {
01291              printf ("failed to set rounding mode to %s\n", mstr);
01292              result = 1;
01293              break;
01294            }
01295          d5 = ld5 * i;
01296          (void) &d5;
01297          fesetround (oldmode);
01298          if (d5 != ((j == 0 && i == 8) ? 0 : (i + k) / 16)
01299                   * nextafter (0.0, 1.0))
01300            {
01301              printf ("%La incorrectly rounded to %s as %a\n",
01302                     ld5 * i, mstr, d5);
01303              result = 1;
01304            }
01305        }
01306     }
01307 
01308   volatile long double ld7 = nextafterl (0.0L, 1.0L);
01309   volatile double d7;
01310   (void) &ld7;
01311   fesetround (FE_UPWARD);
01312   d7 = ld7;
01313   (void) &d7;
01314   fesetround (oldmode);
01315 
01316   if (d7 != nextafter (0.0, 1.0))
01317     {
01318       printf ("%La incorrectly rounded upward to %a\n", ld7, d7);
01319       result = 1;
01320     }
01321 #endif
01322 
01323   return result;
01324 }