[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master e28a374: Simplify by assuming C99 math.h isnan etc.
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master e28a374: Simplify by assuming C99 math.h isnan etc. |
Date: |
Wed, 1 Aug 2018 02:49:01 -0400 (EDT) |
branch: master
commit e28a37438d4ba71cd8a053e956686ab29ff97b6a
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
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 c8beeda..aaccb67 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 e7d404a..45e786f 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/>. */
#include <count-leading-zeros.h>
-#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 7159195..da6ec1a 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/>. */
#include <c-ctype.h>
#include <float.h>
#include <ftoastr.h>
+#include <math.h>
#ifdef WINDOWSNT
# include <sys/socket.h> /* 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. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master e28a374: Simplify by assuming C99 math.h isnan etc.,
Paul Eggert <=