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.
This commit is contained in:
Paul Eggert 2018-07-31 23:46:57 -07:00 committed by Paul Eggert
parent 1804fece02
commit e28a37438d
3 changed files with 6 additions and 25 deletions

View file

@ -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)

View file

@ -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

View file

@ -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. */