From e2e85d14065d0ec417570bf398dc19ab87ff366f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 23 Apr 2009 23:20:59 +0200 Subject: [PATCH] Don't use raw divisions by zero in `test-conversion.c'. * test-suite/standalone/test-conversion.c (ieee_init): New function. (guile_Inf, guile_NaN): New variables. (test_from_double, test_to_double): Use them. Divisions by zero made `cc' on Tru64 5.1b ("Compaq C V6.5-011") bail out and led to a floating point exception when compiled with GCC on the same platform. (main): Call `ieee_init ()'. --- test-suite/standalone/test-conversion.c | 56 ++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/test-suite/standalone/test-conversion.c b/test-suite/standalone/test-conversion.c index afaa2ecc4..41f99d3bc 100644 --- a/test-suite/standalone/test-conversion.c +++ b/test-suite/standalone/test-conversion.c @@ -818,15 +818,60 @@ test_9 (double val, const char *result) } } +/* The `infinity' and `not-a-number' values. */ +static double guile_Inf, guile_NaN; + +/* Initialize GUILE_INF and GUILE_NAN. Taken from `guile_ieee_init ()' in + `libguile/numbers.c'. */ +static void +ieee_init (void) +{ +#ifdef INFINITY + /* C99 INFINITY, when available. + FIXME: The standard allows for INFINITY to be something that overflows + at compile time. We ought to have a configure test to check for that + before trying to use it. (But in practice we believe this is not a + problem on any system guile is likely to target.) */ + guile_Inf = INFINITY; +#elif HAVE_DINFINITY + /* OSF */ + extern unsigned int DINFINITY[2]; + guile_Inf = (*((double *) (DINFINITY))); +#else + double tmp = 1e+10; + guile_Inf = tmp; + for (;;) + { + guile_Inf *= 1e+10; + if (guile_Inf == tmp) + break; + tmp = guile_Inf; + } +#endif + +#ifdef NAN + /* C99 NAN, when available */ + guile_NaN = NAN; +#elif HAVE_DQNAN + { + /* OSF */ + extern unsigned int DQNAN[2]; + guile_NaN = (*((double *)(DQNAN))); + } +#else + guile_NaN = guile_Inf / guile_Inf; +#endif +} + static void test_from_double () { test_9 (12, "12.0"); test_9 (0.25, "0.25"); test_9 (0.1, "0.1"); - test_9 (1.0/0.0, "+inf.0"); - test_9 (-1.0/0.0, "-inf.0"); - test_9 (0.0/0.0, "+nan.0"); + test_9 (guile_Inf, "+inf.0"); + test_9 (-guile_Inf, "-inf.0"); + test_9 (guile_NaN, "+nan.0"); } typedef struct { @@ -880,8 +925,8 @@ test_to_double () test_10 ("12", 12.0, 0); test_10 ("0.25", 0.25, 0); test_10 ("1/4", 0.25, 0); - test_10 ("+inf.0", 1.0/0.0, 0); - test_10 ("-inf.0", -1.0/0.0, 0); + test_10 ("+inf.0", guile_Inf, 0); + test_10 ("-inf.0",-guile_Inf, 0); test_10 ("+1i", 0.0, 1); } @@ -1056,6 +1101,7 @@ tests (void *data, int argc, char **argv) int main (int argc, char *argv[]) { + ieee_init (); scm_boot_guile (argc, argv, tests, NULL); return 0; } -- 2.20.1