aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2018-07-31 23:46:57 -0700
committerPaul Eggert2018-07-31 23:48:56 -0700
commite28a37438d4ba71cd8a053e956686ab29ff97b6a (patch)
tree77c7f4cb879dd8da7925531209222e96834dd711 /src
parent1804fece02691798394c9e9bd519cd4a53776018 (diff)
downloademacs-e28a37438d4ba71cd8a053e956686ab29ff97b6a.tar.gz
emacs-e28a37438d4ba71cd8a053e956686ab29ff97b6a.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/data.c4
-rw-r--r--src/floatfns.c7
-rw-r--r--src/print.c20
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)
2812 return val; 2812 return val;
2813} 2813}
2814 2814
2815#ifndef isnan
2816# define isnan(x) ((x) != (x))
2817#endif
2818
2819static Lisp_Object 2815static Lisp_Object
2820float_arith_driver (double accum, ptrdiff_t argnum, enum arithop code, 2816float_arith_driver (double accum, ptrdiff_t argnum, enum arithop code,
2821 ptrdiff_t nargs, Lisp_Object *args) 2817 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 <https://www.gnu.org/licenses/>. */
47 47
48#include <count-leading-zeros.h> 48#include <count-leading-zeros.h>
49 49
50#ifndef isfinite
51# define isfinite(x) ((x) - (x) == 0)
52#endif
53#ifndef isnan
54# define isnan(x) ((x) != (x))
55#endif
56
57/* Check that X is a floating point number. */ 50/* Check that X is a floating point number. */
58 51
59static void 52static 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 <https://www.gnu.org/licenses/>. */
38#include <c-ctype.h> 38#include <c-ctype.h>
39#include <float.h> 39#include <float.h>
40#include <ftoastr.h> 40#include <ftoastr.h>
41#include <math.h>
41 42
42#ifdef WINDOWSNT 43#ifdef WINDOWSNT
43# include <sys/socket.h> /* for F_DUPFD_CLOEXEC */ 44# include <sys/socket.h> /* for F_DUPFD_CLOEXEC */
@@ -1001,23 +1002,14 @@ float_to_string (char *buf, double data)
1001 int width; 1002 int width;
1002 int len; 1003 int len;
1003 1004
1004 /* Check for plus infinity in a way that won't lose 1005 if (isinf (data))
1005 if there is no plus infinity. */
1006 if (data == data / 2 && data > 1.0)
1007 {
1008 static char const infinity_string[] = "1.0e+INF";
1009 strcpy (buf, infinity_string);
1010 return sizeof infinity_string - 1;
1011 }
1012 /* Likewise for minus infinity. */
1013 if (data == data / 2 && data < -1.0)
1014 { 1006 {
1015 static char const minus_infinity_string[] = "-1.0e+INF"; 1007 static char const minus_infinity_string[] = "-1.0e+INF";
1016 strcpy (buf, minus_infinity_string); 1008 bool positive = 0 < data;
1017 return sizeof minus_infinity_string - 1; 1009 strcpy (buf, minus_infinity_string + positive);
1010 return sizeof minus_infinity_string - 1 - positive;
1018 } 1011 }
1019 /* Check for NaN in a way that won't fail if there are no NaNs. */ 1012 if (isnan (data))
1020 if (! (data * 0.0 >= 0.0))
1021 { 1013 {
1022 /* Prepend "-" if the NaN's sign bit is negative. 1014 /* Prepend "-" if the NaN's sign bit is negative.
1023 The sign bit of a double is the bit that is 1 in -0.0. */ 1015 The sign bit of a double is the bit that is 1 in -0.0. */