From 06ef7ef9193810369b351b00548cfaa48fad0952 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 27 Feb 2012 04:03:02 +0100 Subject: [PATCH] modfl-ieee: Fix test failures. * lib/modfl.c (modfl): Treat NaN and Inf specially. * modules/modfl (Depends-on): Add isfinite, isinf. --- ChangeLog | 4 ++++ lib/modfl.c | 22 +++++++++++++++++++--- modules/modfl | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e0fc21e6..764a1a04b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2012-02-26 Bruno Haible + modfl-ieee: Fix test failures. + * lib/modfl.c (modfl): Treat NaN and Inf specially. + * modules/modfl (Depends-on): Add isfinite, isinf. + modff-ieee: Work around test failures on *BSD, IRIX, OSF/1, etc. * m4/modff-ieee.m4: New file. * m4/modff.m4 (gl_FUNC_MODFF): If gl_FUNC_MODFF_IEEE is present, test diff --git a/lib/modfl.c b/lib/modfl.c index 770294b39..65e324600 100644 --- a/lib/modfl.c +++ b/lib/modfl.c @@ -35,9 +35,25 @@ modfl (long double x, long double *iptr) long double modfl (long double x, long double *iptr) { - long double integer_part = truncl (x); - *iptr = integer_part; - return x - integer_part; + if (isfinite (x)) + { + long double integer_part = truncl (x); + *iptr = integer_part; + return x - integer_part; + } + else + { + if (isinf (x)) + { + *iptr = x; + return 1.0L / x; + } + else /* isnanl (x) */ + { + *iptr = x; + return x; + } + } } #endif diff --git a/modules/modfl b/modules/modfl index 0c6f53b68..3456a4c58 100644 --- a/modules/modfl +++ b/modules/modfl @@ -9,7 +9,9 @@ m4/mathfunc.m4 Depends-on: math modf [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +isfinite [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] truncl [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +isinf [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] configure.ac: gl_FUNC_MODFL -- 2.11.0