From e28a37438d4ba71cd8a053e956686ab29ff97b6a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 31 Jul 2018 23:46:57 -0700 Subject: [PATCH] Simplify by assuming C99 math.h isnan etc. These should be portable nowadays. * src/data.c (isnan): Remove. * src/floatfns.c (isfinite, isnan): Remove. * src/print.c: Include math.h, for isinf and isnan. (float_to_string): Simplify by using them. --- src/data.c | 4 ---- src/floatfns.c | 7 ------- src/print.c | 20 ++++++-------------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/data.c b/src/data.c index c8beeda7208..aaccb675183 100644 --- a/src/data.c +++ b/src/data.c @@ -2812,10 +2812,6 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args) return val; } -#ifndef isnan -# define isnan(x) ((x) != (x)) -#endif - static Lisp_Object float_arith_driver (double accum, ptrdiff_t argnum, enum arithop code, ptrdiff_t nargs, Lisp_Object *args) diff --git a/src/floatfns.c b/src/floatfns.c index e7d404a84e0..45e786f9669 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -47,13 +47,6 @@ along with GNU Emacs. If not, see . */ #include -#ifndef isfinite -# define isfinite(x) ((x) - (x) == 0) -#endif -#ifndef isnan -# define isnan(x) ((x) != (x)) -#endif - /* Check that X is a floating point number. */ static void diff --git a/src/print.c b/src/print.c index 71591952a23..da6ec1aaedf 100644 --- a/src/print.c +++ b/src/print.c @@ -38,6 +38,7 @@ along with GNU Emacs. If not, see . */ #include #include #include +#include #ifdef WINDOWSNT # include /* for F_DUPFD_CLOEXEC */ @@ -1001,23 +1002,14 @@ float_to_string (char *buf, double data) int width; int len; - /* Check for plus infinity in a way that won't lose - if there is no plus infinity. */ - if (data == data / 2 && data > 1.0) - { - static char const infinity_string[] = "1.0e+INF"; - strcpy (buf, infinity_string); - return sizeof infinity_string - 1; - } - /* Likewise for minus infinity. */ - if (data == data / 2 && data < -1.0) + if (isinf (data)) { static char const minus_infinity_string[] = "-1.0e+INF"; - strcpy (buf, minus_infinity_string); - return sizeof minus_infinity_string - 1; + bool positive = 0 < data; + strcpy (buf, minus_infinity_string + positive); + return sizeof minus_infinity_string - 1 - positive; } - /* Check for NaN in a way that won't fail if there are no NaNs. */ - if (! (data * 0.0 >= 0.0)) + if (isnan (data)) { /* Prepend "-" if the NaN's sign bit is negative. The sign bit of a double is the bit that is 1 in -0.0. */ -- 2.39.2