X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-trunc2.c;h=c9f0d8fdd675a5d45df0f4ccad11755df705899a;hb=12f12a9c5b08fb25c6212f37a62b218f4b5bb5a8;hp=c06846d31756164e1544c47f4534f5c13908f5d0;hpb=b17d7ac7df62c7c7f56fe857ed28151d8b0e4e28;p=gnulib.git diff --git a/tests/test-trunc2.c b/tests/test-trunc2.c index c06846d31..c9f0d8fdd 100644 --- a/tests/test-trunc2.c +++ b/tests/test-trunc2.c @@ -1,5 +1,5 @@ /* Test of rounding towards zero. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,9 @@ /* Written by Bruno Haible , 2007. */ +/* When this test fails on some platform, build it together with the gnulib + module 'fprintf-posix' for optimal debugging output. */ + #include #include @@ -24,20 +27,9 @@ #include #include #include -#include - -#include "isnand.h" -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - abort (); \ - } \ - } \ - while (0) +#include "isnand-nolibm.h" +#include "macros.h" /* The reference implementation, taken from lib/trunc.c. */ @@ -73,27 +65,27 @@ trunc_reference (DOUBLE x) { /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } return z; } @@ -113,11 +105,11 @@ correct_result_p (DOUBLE x, DOUBLE result) return (x >= 0 ? (x < 1 ? result == L_(0.0) : - x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 : - equal (result, x)) + x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 : + equal (result, x)) : (x > -1 ? result == L_(0.0) : - x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 : - equal (result, x))); + x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 : + equal (result, x))); } /* Test the function for a given argument. */ @@ -134,9 +126,11 @@ check (double x) return 0; else { - fprintf (stderr, "trunc %g(%a) = %g(%a) or %g(%a)?\n", - x, x, reference, reference, result, result); - return 1; +#if GNULIB_TEST_FPRINTF_POSIX + fprintf (stderr, "trunc %g(%a) = %g(%a) or %g(%a)?\n", + x, x, reference, reference, result, result); +#endif + return 1; } } } @@ -153,14 +147,14 @@ main () for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++) for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++) { - /* Combine highbits and lowbits into a floating-point number, - sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ - union { double f; uint64_t i; } janus; - janus.i = ((uint64_t) highbits << (64 - NUM_HIGHBITS)) - | ((uint64_t) ((int64_t) ((uint64_t) lowbits << (64 - NUM_LOWBITS)) - >> (64 - NUM_LOWBITS - NUM_HIGHBITS)) - >> NUM_HIGHBITS); - error |= check (janus.f); + /* Combine highbits and lowbits into a floating-point number, + sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ + union { double f; uint64_t i; } janus; + janus.i = ((uint64_t) highbits << (64 - NUM_HIGHBITS)) + | ((uint64_t) ((int64_t) ((uint64_t) lowbits << (64 - NUM_LOWBITS)) + >> (64 - NUM_LOWBITS - NUM_HIGHBITS)) + >> NUM_HIGHBITS); + error |= check (janus.f); } return (error ? 1 : 0); }