123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206 |
- /* Miscellaneous tests which don't fit anywhere else.
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
- #include <fenv.h>
- #include <float.h>
- #include <ieee754.h>
- #include <math.h>
- #include <stdio.h>
- #include <string.h>
- #include "math-tests.h"
- static int
- do_test (void)
- {
- int result = 0;
- #ifndef NO_LONG_DOUBLE
- {
- long double x = 0x100000001ll + (long double) 0.5;
- long double q;
- long double r;
- r = modfl (x, &q);
- if (q != (long double) 0x100000001ll || r != 0.5)
- {
- printf ("modfl (%Lg, ...) failed\n", x);
- result = 1;
- }
- }
- {
- long double x;
- long double m;
- long double r;
- int e;
- int i;
- # if LDBL_MANT_DIG == 64
- m = 0xf.fffffffffffffffp-4L;
- # elif LDBL_MANT_DIG == 106
- /* This has to match the mantissa of LDBL_MAX which actually does have a
- missing bit in the middle. */
- m = 0x1.fffffffffffff7ffffffffffff8p-1L;
- # elif LDBL_MANT_DIG == 113
- m = 0x1.ffffffffffffffffffffffffffffp-1L;
- # else
- # error "Please adjust"
- # endif
- for (i = LDBL_MAX_EXP, x = LDBL_MAX; i >= LDBL_MIN_EXP; --i, x /= 2.0L)
- {
- printf ("2^%d: ", i);
- r = frexpl (x, &e);
- if (r != m)
- {
- printf ("mantissa incorrect: %.20La\n", r);
- result = 1;
- continue;
- }
- if (e != i)
- {
- printf ("exponent wrong %d (%.20Lg)\n", e, x);
- result = 1;
- continue;
- }
- puts ("ok");
- }
- for (i = LDBL_MIN_EXP, x = LDBL_MIN; i >= LDBL_MIN_EXP - LDBL_MANT_DIG + 1;
- --i, x /= 2.0L)
- {
- printf ("2^%d: ", i);
- r = frexpl (x, &e);
- if (r != 0.5L)
- {
- printf ("mantissa incorrect: %.20La\n", r);
- result = 1;
- continue;
- }
- if (e != i)
- {
- printf ("exponent wrong %d (%.20Lg)\n", e, x);
- result = 1;
- continue;
- }
- puts ("ok");
- }
- }
- # if 0
- {
- int e;
- long double r = frexpl (LDBL_MIN * LDBL_EPSILON, &e);
- if (r != 0.5)
- {
- printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): mantissa wrong: %Lg\n",
- r);
- result = 1;
- }
- else if (e != -16444)
- {
- printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): exponent wrong: %d\n",
- e);
- result = 1;
- }
- }
- # endif
- #endif
- {
- double x = 0x100000001ll + (double) 0.5;
- double q;
- double r;
- r = modf (x, &q);
- if (q != (double) 0x100000001ll || r != 0.5)
- {
- printf ("modf (%g, ...) failed\n", x);
- result = 1;
- }
- }
- {
- union ieee754_float v1;
- union ieee754_float v2;
- float f;
- v1.f = f = FLT_MIN;
- if (fpclassify (f) != FP_NORMAL)
- {
- printf ("fpclassify (FLT_MIN) failed: %d\n", fpclassify (f));
- result = 1;
- }
- f = nextafterf (f, FLT_MIN / 2.0f);
- if (fpclassify (f) != FP_SUBNORMAL)
- {
- printf ("fpclassify (FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
- result = 1;
- }
- v2.f = f = nextafterf (f, FLT_MIN);
- if (fpclassify (f) != FP_NORMAL)
- {
- printf ("fpclassify (FLT_MIN-epsilon+epsilon) failed: %d\n",
- fpclassify (f));
- result = 1;
- }
- if (v1.ieee.mantissa != v2.ieee.mantissa)
- {
- printf ("FLT_MIN: mantissa differs: %8x vs %8x\n",
- v1.ieee.mantissa, v2.ieee.mantissa);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("FLT_MIN: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("FLT_MIN: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.f = f = -FLT_MIN;
- if (fpclassify (f) != FP_NORMAL)
- {
- printf ("fpclassify (-FLT_MIN) failed: %d\n", fpclassify (f));
- result = 1;
- }
- f = nextafterf (f, -FLT_MIN / 2.0f);
- if (fpclassify (f) != FP_SUBNORMAL)
- {
- printf ("fpclassify (-FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
- result = 1;
- }
- v2.f = f = nextafterf (f, -FLT_MIN);
- if (fpclassify (f) != FP_NORMAL)
- {
- printf ("fpclassify (-FLT_MIN-epsilon+epsilon) failed: %d\n",
- fpclassify (f));
- result = 1;
- }
- if (v1.ieee.mantissa != v2.ieee.mantissa)
- {
- printf ("-FLT_MIN: mantissa differs: %8x vs %8x\n",
- v1.ieee.mantissa, v2.ieee.mantissa);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("-FLT_MIN: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("-FLT_MIN: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- f = FLT_MAX;
- if (fpclassify (f) != FP_NORMAL)
- {
- printf ("fpclassify (FLT_MAX) failed: %d\n", fpclassify (f));
- result = 1;
- }
- f = nextafterf (f, INFINITY);
- if (fpclassify (f) != FP_INFINITE)
- {
- printf ("fpclassify (FLT_MAX+epsilon) failed: %d\n", fpclassify (f));
- result = 1;
- }
- f = -FLT_MAX;
- if (fpclassify (f) != FP_NORMAL)
- {
- printf ("fpclassify (-FLT_MAX) failed: %d\n", fpclassify (f));
- result = 1;
- }
- f = nextafterf (f, -INFINITY);
- if (fpclassify (f) != FP_INFINITE)
- {
- printf ("fpclassify (-FLT_MAX-epsilon) failed: %d\n", fpclassify (f));
- result = 1;
- }
- v1.f = f = 0.0625;
- f = nextafterf (f, 0.0);
- v2.f = f = nextafterf (f, 1.0);
- if (v1.ieee.mantissa != v2.ieee.mantissa)
- {
- printf ("0.0625f down: mantissa differs: %8x vs %8x\n",
- v1.ieee.mantissa, v2.ieee.mantissa);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("0.0625f down: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("0.0625f down: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.f = f = 0.0625;
- f = nextafterf (f, 1.0);
- v2.f = f = nextafterf (f, 0.0);
- if (v1.ieee.mantissa != v2.ieee.mantissa)
- {
- printf ("0.0625f up: mantissa differs: %8x vs %8x\n",
- v1.ieee.mantissa, v2.ieee.mantissa);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("0.0625f up: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("0.0625f up: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.f = f = -0.0625;
- f = nextafterf (f, 0.0);
- v2.f = f = nextafterf (f, -1.0);
- if (v1.ieee.mantissa != v2.ieee.mantissa)
- {
- printf ("-0.0625f up: mantissa differs: %8x vs %8x\n",
- v1.ieee.mantissa, v2.ieee.mantissa);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("-0.0625f up: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("-0.0625f up: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.f = f = -0.0625;
- f = nextafterf (f, -1.0);
- v2.f = f = nextafterf (f, 0.0);
- if (v1.ieee.mantissa != v2.ieee.mantissa)
- {
- printf ("-0.0625f down: mantissa differs: %8x vs %8x\n",
- v1.ieee.mantissa, v2.ieee.mantissa);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("-0.0625f down: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("-0.0625f down: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.f = f = 0.0f;
- f = nextafterf (f, 1.0);
- v2.f = nextafterf (f, -1.0);
- if (v1.ieee.mantissa != v2.ieee.mantissa)
- {
- printf ("0.0f up: mantissa differs: %8x vs %8x\n",
- v1.ieee.mantissa, v2.ieee.mantissa);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("0.0f up: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (0 != v2.ieee.negative)
- {
- printf ("0.0f up: negative differs: 0 vs %d\n",
- v2.ieee.negative);
- result = 1;
- }
- v1.f = f = 0.0f;
- f = nextafterf (f, -1.0);
- v2.f = nextafterf (f, 1.0);
- if (v1.ieee.mantissa != v2.ieee.mantissa)
- {
- printf ("0.0f down: mantissa differs: %8x vs %8x\n",
- v1.ieee.mantissa, v2.ieee.mantissa);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("0.0f down: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (1 != v2.ieee.negative)
- {
- printf ("0.0f down: negative differs: 1 vs %d\n",
- v2.ieee.negative);
- result = 1;
- }
- if (nextafterf (0.0f, INFINITY) != nextafterf (0.0f, 1.0f)
- || nextafterf (-0.0f, INFINITY) != nextafterf (-0.0f, 1.0f)
- || nextafterf (0.0f, -INFINITY) != nextafterf (0.0f, -1.0f)
- || nextafterf (-0.0f, -INFINITY) != nextafterf (-0.0f, -1.0f))
- {
- printf ("nextafterf (+-0, +-Inf) != nextafterf (+-0, +-1)\n");
- result = 1;
- }
- if (nexttowardf (0.0f, INFINITY) != nexttowardf (0.0f, 1.0f)
- || nexttowardf (-0.0f, INFINITY) != nexttowardf (-0.0f, 1.0f)
- || nexttowardf (0.0f, -INFINITY) != nexttowardf (0.0f, -1.0f)
- || nexttowardf (-0.0f, -INFINITY) != nexttowardf (-0.0f, -1.0f))
- {
- printf ("nexttowardf (+-0, +-Inf) != nexttowardf (+-0, +-1)\n");
- result = 1;
- }
- }
- {
- union ieee754_double v1;
- union ieee754_double v2;
- double d;
- v1.d = d = DBL_MIN;
- if (fpclassify (d) != FP_NORMAL)
- {
- printf ("fpclassify (DBL_MIN) failed: %d\n", fpclassify (d));
- result = 1;
- }
- d = nextafter (d, DBL_MIN / 2.0);
- if (fpclassify (d) != FP_SUBNORMAL)
- {
- printf ("fpclassify (DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
- result = 1;
- }
- v2.d = d = nextafter (d, DBL_MIN);
- if (fpclassify (d) != FP_NORMAL)
- {
- printf ("fpclassify (DBL_MIN-epsilon+epsilon) failed: %d\n",
- fpclassify (d));
- result = 1;
- }
- if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
- {
- printf ("DBL_MIN: mantissa0 differs: %8x vs %8x\n",
- v1.ieee.mantissa0, v2.ieee.mantissa0);
- result = 1;
- }
- if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
- {
- printf ("DBL_MIN: mantissa1 differs: %8x vs %8x\n",
- v1.ieee.mantissa1, v2.ieee.mantissa1);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("DBL_MIN: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("DBL_MIN: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.d = d = -DBL_MIN;
- if (fpclassify (d) != FP_NORMAL)
- {
- printf ("fpclassify (-DBL_MIN) failed: %d\n", fpclassify (d));
- result = 1;
- }
- d = nextafter (d, -DBL_MIN / 2.0);
- if (fpclassify (d) != FP_SUBNORMAL)
- {
- printf ("fpclassify (-DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
- result = 1;
- }
- v2.d = d = nextafter (d, -DBL_MIN);
- if (fpclassify (d) != FP_NORMAL)
- {
- printf ("fpclassify (-DBL_MIN-epsilon+epsilon) failed: %d\n",
- fpclassify (d));
- result = 1;
- }
- if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
- {
- printf ("-DBL_MIN: mantissa0 differs: %8x vs %8x\n",
- v1.ieee.mantissa0, v2.ieee.mantissa0);
- result = 1;
- }
- if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
- {
- printf ("-DBL_MIN: mantissa1 differs: %8x vs %8x\n",
- v1.ieee.mantissa1, v2.ieee.mantissa1);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("-DBL_MIN: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("-DBL_MIN: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- d = DBL_MAX;
- if (fpclassify (d) != FP_NORMAL)
- {
- printf ("fpclassify (DBL_MAX) failed: %d\n", fpclassify (d));
- result = 1;
- }
- d = nextafter (d, INFINITY);
- if (fpclassify (d) != FP_INFINITE)
- {
- printf ("fpclassify (DBL_MAX+epsilon) failed: %d\n", fpclassify (d));
- result = 1;
- }
- d = -DBL_MAX;
- if (fpclassify (d) != FP_NORMAL)
- {
- printf ("fpclassify (-DBL_MAX) failed: %d\n", fpclassify (d));
- result = 1;
- }
- d = nextafter (d, -INFINITY);
- if (fpclassify (d) != FP_INFINITE)
- {
- printf ("fpclassify (-DBL_MAX-epsilon) failed: %d\n", fpclassify (d));
- result = 1;
- }
- v1.d = d = 0.0625;
- d = nextafter (d, 0.0);
- v2.d = d = nextafter (d, 1.0);
- if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
- {
- printf ("0.0625 down: mantissa0 differs: %8x vs %8x\n",
- v1.ieee.mantissa0, v2.ieee.mantissa0);
- result = 1;
- }
- if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
- {
- printf ("0.0625 down: mantissa1 differs: %8x vs %8x\n",
- v1.ieee.mantissa1, v2.ieee.mantissa1);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("0.0625 down: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("0.0625 down: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.d = d = 0.0625;
- d = nextafter (d, 1.0);
- v2.d = d = nextafter (d, 0.0);
- if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
- {
- printf ("0.0625 up: mantissa0 differs: %8x vs %8x\n",
- v1.ieee.mantissa0, v2.ieee.mantissa0);
- result = 1;
- }
- if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
- {
- printf ("0.0625 up: mantissa1 differs: %8x vs %8x\n",
- v1.ieee.mantissa1, v2.ieee.mantissa1);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("0.0625 up: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("0.0625 up: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.d = d = -0.0625;
- d = nextafter (d, 0.0);
- v2.d = d = nextafter (d, -1.0);
- if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
- {
- printf ("-0.0625 up: mantissa0 differs: %8x vs %8x\n",
- v1.ieee.mantissa0, v2.ieee.mantissa0);
- result = 1;
- }
- if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
- {
- printf ("-0.0625 up: mantissa1 differs: %8x vs %8x\n",
- v1.ieee.mantissa1, v2.ieee.mantissa1);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("-0.0625 up: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("-0.0625 up: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.d = d = -0.0625;
- d = nextafter (d, -1.0);
- v2.d = d = nextafter (d, 0.0);
- if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
- {
- printf ("-0.0625 down: mantissa0 differs: %8x vs %8x\n",
- v1.ieee.mantissa0, v2.ieee.mantissa0);
- result = 1;
- }
- if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
- {
- printf ("-0.0625 down: mantissa1 differs: %8x vs %8x\n",
- v1.ieee.mantissa1, v2.ieee.mantissa1);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("-0.0625 down: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (v1.ieee.negative != v2.ieee.negative)
- {
- printf ("-0.0625 down: negative differs: %d vs %d\n",
- v1.ieee.negative, v2.ieee.negative);
- result = 1;
- }
- v1.d = d = 0.0;
- d = nextafter (d, 1.0);
- v2.d = nextafter (d, -1.0);
- if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
- {
- printf ("0.0 up: mantissa0 differs: %8x vs %8x\n",
- v1.ieee.mantissa0, v2.ieee.mantissa0);
- result = 1;
- }
- if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
- {
- printf ("0.0 up: mantissa1 differs: %8x vs %8x\n",
- v1.ieee.mantissa1, v2.ieee.mantissa1);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("0.0 up: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (0 != v2.ieee.negative)
- {
- printf ("0.0 up: negative differs: 0 vs %d\n",
- v2.ieee.negative);
- result = 1;
- }
- v1.d = d = 0.0;
- d = nextafter (d, -1.0);
- v2.d = nextafter (d, 1.0);
- if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
- {
- printf ("0.0 down: mantissa0 differs: %8x vs %8x\n",
- v1.ieee.mantissa0, v2.ieee.mantissa0);
- result = 1;
- }
- if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
- {
- printf ("0.0 down: mantissa1 differs: %8x vs %8x\n",
- v1.ieee.mantissa1, v2.ieee.mantissa1);
- result = 1;
- }
- if (v1.ieee.exponent != v2.ieee.exponent)
- {
- printf ("0.0 down: exponent differs: %4x vs %4x\n",
- v1.ieee.exponent, v2.ieee.exponent);
- result = 1;
- }
- if (1 != v2.ieee.negative)
- {
- printf ("0.0 down: negative differs: 1 vs %d\n",
- v2.ieee.negative);
- result = 1;
- }
- if (nextafter (0.0, INFINITY) != nextafter (0.0, 1.0)
- || nextafter (-0.0, INFINITY) != nextafter (-0.0, 1.0)
- || nextafter (0.0, -INFINITY) != nextafter (0.0, -1.0)
- || nextafter (-0.0, -INFINITY) != nextafter (-0.0, -1.0))
- {
- printf ("nextafter (+-0, +-Inf) != nextafter (+-0, +-1)\n");
- result = 1;
- }
- if (nexttoward (0.0, INFINITY) != nexttoward (0.0, 1.0)
- || nexttoward (-0.0, INFINITY) != nexttoward (-0.0, 1.0)
- || nexttoward (0.0, -INFINITY) != nexttoward (0.0, -1.0)
- || nexttoward (-0.0, -INFINITY) != nexttoward (-0.0, -1.0))
- {
- printf ("nexttoward (+-0, +-Inf) != nexttoward (+-0, +-1)\n");
- result = 1;
- }
- }
- #ifndef NO_LONG_DOUBLE
- {
- long double v1, v2;
- v1 = LDBL_MIN;
- if (fpclassify (v1) != FP_NORMAL)
- {
- printf ("fpclassify (LDBL_MIN) failed: %d (%La)\n",
- fpclassify (v1), v1);
- result = 1;
- }
- v2 = nextafterl (v1, LDBL_MIN / 2.0);
- if (fpclassify (v2) != FP_SUBNORMAL)
- {
- printf ("fpclassify (LDBL_MIN-epsilon) failed: %d (%La)\n",
- fpclassify (v2), v2);
- result = 1;
- }
- v2 = nextafterl (v2, LDBL_MIN);
- if (fpclassify (v2) != FP_NORMAL)
- {
- printf ("fpclassify (LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
- fpclassify (v2), v2);
- result = 1;
- }
- if (v1 != v2)
- {
- printf ("LDBL_MIN-epsilon+epsilon != LDBL_MIN: %La vs %La\n", v2, v1);
- result = 1;
- }
- v1 = -LDBL_MIN;
- if (fpclassify (v1) != FP_NORMAL)
- {
- printf ("fpclassify (-LDBL_MIN) failed: %d (%La)\n",
- fpclassify (v1), v1);
- result = 1;
- }
- v2 = nextafterl (v1, -LDBL_MIN / 2.0);
- if (fpclassify (v2) != FP_SUBNORMAL)
- {
- printf ("fpclassify (-LDBL_MIN-epsilon) failed: %d (%La)\n",
- fpclassify (v2), v2);
- result = 1;
- }
- v2 = nextafterl (v2, -LDBL_MIN);
- if (fpclassify (v2) != FP_NORMAL)
- {
- printf ("fpclassify (-LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
- fpclassify (v2), v2);
- result = 1;
- }
- if (v1 != v2)
- {
- printf ("-LDBL_MIN-epsilon+epsilon != -LDBL_MIN: %La vs %La\n", v2, v1);
- result = 1;
- }
- v1 = LDBL_MAX;
- if (fpclassify (v1) != FP_NORMAL)
- {
- printf ("fpclassify (LDBL_MAX) failed: %d (%La)\n",
- fpclassify (v1), v1);
- result = 1;
- }
- v2 = nextafterl (v1, INFINITY);
- if (fpclassify (v2) != FP_INFINITE)
- {
- printf ("fpclassify (LDBL_MAX+epsilon) failed: %d (%La)\n",
- fpclassify (v2), v2);
- result = 1;
- }
- v1 = -LDBL_MAX;
- if (fpclassify (v1) != FP_NORMAL)
- {
- printf ("fpclassify (-LDBL_MAX) failed: %d (%La)\n",
- fpclassify (v1), v1);
- result = 1;
- }
- v2 = nextafterl (v1, -INFINITY);
- if (fpclassify (v2) != FP_INFINITE)
- {
- printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d (%La)\n",
- fpclassify (v2), v2);
- result = 1;
- }
- v1 = 0.0625;
- v2 = nextafterl (v1, 0.0);
- v2 = nextafterl (v2, 1.0);
- if (v1 != v2)
- {
- printf ("0.0625L-epsilon+epsilon != 0.0625L: %La vs %La\n", v2, v1);
- result = 1;
- }
- v1 = 0.0625;
- v2 = nextafterl (v1, 1.0);
- v2 = nextafterl (v2, 0.0);
- if (v1 != v2)
- {
- printf ("0.0625L+epsilon-epsilon != 0.0625L: %La vs %La\n", v2, v1);
- result = 1;
- }
- v1 = -0.0625;
- v2 = nextafterl (v1, 0.0);
- v2 = nextafterl (v2, -1.0);
- if (v1 != v2)
- {
- printf ("-0.0625L+epsilon-epsilon != -0.0625L: %La vs %La\n", v2, v1);
- result = 1;
- }
- v1 = -0.0625;
- v2 = nextafterl (v1, -1.0);
- v2 = nextafterl (v2, 0.0);
- if (v1 != v2)
- {
- printf ("-0.0625L-epsilon+epsilon != -0.0625L: %La vs %La\n", v2, v1);
- result = 1;
- }
- v1 = 0.0;
- v2 = nextafterl (v1, 1.0);
- v2 = nextafterl (v2, -1.0);
- if (v1 != v2)
- {
- printf ("0.0+epsilon-epsilon != 0.0L: %La vs %La\n", v2, v1);
- result = 1;
- }
- if (signbit (v2))
- {
- printf ("0.0+epsilon-epsilon is negative\n");
- result = 1;
- }
- v1 = 0.0;
- v2 = nextafterl (v1, -1.0);
- v2 = nextafterl (v2, 1.0);
- if (v1 != v2)
- {
- printf ("0.0-epsilon+epsilon != 0.0L: %La vs %La\n", v2, v1);
- result = 1;
- }
- if (!signbit (v2))
- {
- printf ("0.0-epsilon+epsilon is positive\n");
- result = 1;
- }
- if (nextafterl (0.0, INFINITY) != nextafterl (0.0, 1.0)
- || nextafterl (-0.0, INFINITY) != nextafterl (-0.0, 1.0)
- || nextafterl (0.0, -INFINITY) != nextafterl (0.0, -1.0)
- || nextafterl (-0.0, -INFINITY) != nextafterl (-0.0, -1.0))
- {
- printf ("nextafterl (+-0, +-Inf) != nextafterl (+-0, +-1)\n");
- result = 1;
- }
- if (nexttowardl (0.0L, INFINITY) != nexttowardl (0.0L, 1.0L)
- || nexttowardl (-0.0L, INFINITY) != nexttowardl (-0.0L, 1.0L)
- || nexttowardl (0.0L, -INFINITY) != nexttowardl (0.0L, -1.0L)
- || nexttowardl (-0.0L, -INFINITY) != nexttowardl (-0.0L, -1.0L))
- {
- printf ("nexttowardl (+-0, +-Inf) != nexttowardl (+-0, +-1)\n");
- result = 1;
- }
- }
- #endif
- if (! isnormal (FLT_MIN))
- {
- puts ("isnormal (FLT_MIN) failed");
- result = 1;
- }
- if (! isnormal (DBL_MIN))
- {
- puts ("isnormal (DBL_MIN) failed");
- result = 1;
- }
- #ifndef NO_LONG_DOUBLE
- if (! isnormal (LDBL_MIN))
- {
- puts ("isnormal (LDBL_MIN) failed");
- result = 1;
- }
- #endif
- #if defined (__i386__) || defined (__x86_64__)
- /* This is a test for the strange long doubles in x86 FPUs. */
- {
- union
- {
- char b[10];
- long double d;
- } u =
- { .b = { 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0 } };
- if (fpclassify (u.d) != FP_NORMAL)
- {
- printf ("fpclassify (0x00008000000000000000) failed: %d (%Lg)\n",
- fpclassify (u.d), u.d);
- result = 1;
- }
- }
- /* Special qNaNs in x86 long double. Test for scalbl. */
- {
- union
- {
- char b[10];
- long double d;
- } u =
- { .b = { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
- long double r;
- r = scalbl (u.d, 0.0);
- if (!isnan (r))
- {
- puts ("scalbl (qNaN, 0) does not return NaN");
- result = 1;
- }
- else if (memcmp (&r, &u.d, sizeof (double)) != 0)
- {
- puts ("scalbl (qNaN, 0) does not return the same NaN");
- result = 1;
- }
- }
- #endif
- #ifndef NO_LONG_DOUBLE
- {
- long double r;
- feclearexcept (FE_ALL_EXCEPT);
- r = scalbl (LDBL_MIN, 2147483647);
- if (! isinf (r))
- {
- puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
- result = 1;
- }
- else if (signbit (r) != 0)
- {
- puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
- result = 1;
- }
- else if (fetestexcept (FE_UNDERFLOW))
- {
- puts ("scalbl (LDBL_MIN, 2147483647) raises underflow exception");
- result = 1;
- }
- feclearexcept (FE_ALL_EXCEPT);
- r = scalbl (LDBL_MAX, -2147483647);
- if (r != 0.0)
- {
- puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
- result = 1;
- }
- else if (signbit (r) != 0)
- {
- puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
- result = 1;
- }
- else if (fetestexcept (FE_OVERFLOW))
- {
- puts ("scalbl (LDBL_MAX, -2147483647) raises overflow exception");
- result = 1;
- }
- }
- #endif
- /* The tests here are very similar to tests earlier in this file,
- the important difference is just that there are no intervening
- union variables that cause some GCC versions to hide possible
- bugs in nextafter* implementation. */
- if (nextafterf (nextafterf (FLT_MIN, FLT_MIN / 2.0), FLT_MIN) != FLT_MIN)
- {
- puts ("nextafterf FLT_MIN test failed");
- result = 1;
- }
- if (nextafterf (nextafterf (-FLT_MIN, -FLT_MIN / 2.0), -FLT_MIN)
- != -FLT_MIN)
- {
- puts ("nextafterf -FLT_MIN test failed");
- result = 1;
- }
- if (nextafter (nextafter (DBL_MIN, DBL_MIN / 2.0), DBL_MIN) != DBL_MIN)
- {
- puts ("nextafter DBL_MIN test failed");
- result = 1;
- }
- if (nextafter (nextafter (-DBL_MIN, -DBL_MIN / 2.0), -DBL_MIN) != -DBL_MIN)
- {
- puts ("nextafter -DBL_MIN test failed");
- result = 1;
- }
- #ifndef NO_LONG_DOUBLE
- if (nextafterl (nextafterl (LDBL_MIN, LDBL_MIN / 2.0), LDBL_MIN)
- != LDBL_MIN)
- {
- puts ("nextafterl LDBL_MIN test failed");
- result = 1;
- }
- if (nextafterl (nextafterl (-LDBL_MIN, -LDBL_MIN / 2.0), -LDBL_MIN)
- != -LDBL_MIN)
- {
- puts ("nextafterl -LDBL_MIN test failed");
- result = 1;
- }
- #endif
- volatile float f1 = FLT_MAX;
- volatile float f2 = FLT_MAX / 2;
- (void) &f1;
- (void) &f2;
- feclearexcept (FE_ALL_EXCEPT);
- f2 += f1;
- #if defined(FE_OVERFLOW) && defined(FE_INEXACT)
- int fe = fetestexcept (FE_ALL_EXCEPT);
- if (EXCEPTION_TESTS (float) && fe != (FE_OVERFLOW | FE_INEXACT))
- {
- printf ("float overflow test failed: %x\n", fe);
- result = 1;
- }
- #endif
- volatile double d1 = DBL_MAX;
- volatile double d2 = DBL_MAX / 2;
- (void) &d1;
- (void) &d2;
- feclearexcept (FE_ALL_EXCEPT);
- d2 += d1;
- #if defined(FE_OVERFLOW) && defined(FE_INEXACT)
- fe = fetestexcept (FE_ALL_EXCEPT);
- if (EXCEPTION_TESTS (double) && fe != (FE_OVERFLOW | FE_INEXACT))
- {
- printf ("double overflow test failed: %x\n", fe);
- result = 1;
- }
- #endif
- #ifndef NO_LONG_DOUBLE
- volatile long double ld1 = LDBL_MAX;
- volatile long double ld2 = LDBL_MAX / 2;
- (void) &ld1;
- (void) &ld2;
- feclearexcept (FE_ALL_EXCEPT);
- ld2 += ld1;
- # if defined(FE_OVERFLOW) && defined(FE_INEXACT)
- fe = fetestexcept (FE_ALL_EXCEPT);
- if (EXCEPTION_TESTS (long double) && fe != (FE_OVERFLOW | FE_INEXACT))
- {
- printf ("long double overflow test failed: %x\n", fe);
- result = 1;
- }
- # endif
- #endif
- #if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG == 113
- volatile long double ld3 = 0x1.0000000000010000000100000001p+1;
- volatile long double ld4 = 0x1.0000000000000000000000000001p+1;
- (void) &ld3;
- (void) &ld4;
- ld3 -= ld4;
- if (ld3 != 0x1.0p-47)
- {
- printf ("long double subtraction test failed %.28La\n", ld3);
- result = 1;
- }
- #endif
- /* Skip testing IBM long double format, for 2 reasons:
- 1) it only supports FE_TONEAREST
- 2) nextafter (0.0, 1.0) == nextafterl (0.0L, 1.0L), so
- nextafter (0.0, 1.0) / 16.0L will be 0.0L. */
- #if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG >= DBL_MANT_DIG + 4 \
- && LDBL_MANT_DIG != 106
- int oldmode = fegetround ();
- int j;
- for (j = 0; j < 4; j++)
- {
- int mode;
- int i;
- int k = 0;
- const char *mstr;
- switch (j)
- {
- #ifdef FE_TONEAREST
- case 0:
- mode = FE_TONEAREST;
- mstr = "nearest";
- k = 8;
- break;
- #endif
- #ifdef FE_DOWNWARD
- case 1:
- mode = FE_DOWNWARD;
- mstr = "-inf";
- break;
- #endif
- #ifdef FE_UPWARD
- case 2:
- mode = FE_UPWARD;
- mstr = "+inf";
- k = 15;
- break;
- #endif
- #ifdef FE_TOWARDZERO
- case 3:
- mode = FE_TOWARDZERO;
- mstr = "0";
- break;
- #endif
- default:
- continue;
- }
- volatile long double ld5 = nextafter (0.0, 1.0) / 16.0L;
- volatile double d5;
- (void) &ld5;
- for (i = 0; i <= 32; i++)
- {
- if (fesetround (mode))
- {
- printf ("failed to set rounding mode to %s\n", mstr);
- if (ROUNDING_TESTS (long double, mode)
- && ROUNDING_TESTS (double, mode))
- result = 1;
- else
- puts ("ignoring this failure");
- break;
- }
- d5 = ld5 * i;
- (void) &d5;
- fesetround (oldmode);
- if (d5 != ((j == 0 && i == 8) ? 0 : (i + k) / 16)
- * nextafter (0.0, 1.0))
- {
- printf ("%La incorrectly rounded to %s as %a\n",
- ld5 * i, mstr, d5);
- if (ROUNDING_TESTS (long double, mode)
- && ROUNDING_TESTS (double, mode))
- result = 1;
- else
- puts ("ignoring this failure");
- }
- }
- }
- volatile long double ld7 = nextafterl (0.0L, 1.0L);
- volatile double d7;
- (void) &ld7;
- fesetround (FE_UPWARD);
- d7 = ld7;
- (void) &d7;
- fesetround (oldmode);
- if (d7 != nextafter (0.0, 1.0))
- {
- printf ("%La incorrectly rounded upward to %a\n", ld7, d7);
- if (ROUNDING_TESTS (long double, FE_UPWARD)
- && ROUNDING_TESTS (double, FE_UPWARD))
- result = 1;
- else
- puts ("ignoring this failure");
- }
- #endif
- return result;
- }
- #define TEST_FUNCTION do_test ()
- #include "../test-skeleton.c"
|