summaryrefslogtreecommitdiff
path: root/src/floatfns.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-03-07 08:29:19 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2017-03-07 08:32:04 -0800
commit14af3395e6d8a2a95268138355ade408743922ac (patch)
tree85a38267025e4af11bb490d89129846273129e2a /src/floatfns.c
parent641ce935b79c63020553f33fc5ca8f4d05e56b0b (diff)
downloademacs-14af3395e6d8a2a95268138355ade408743922ac.tar.gz
Define copysign on all platforms
* configure.ac (copysign): Remove test. * src/floatfns.c (signbit): New macro, if not already defined. (Fcopysign): Use it instead of copysign. (Fcopysign, syms_of_floatfns): Define the function on all platforms.
Diffstat (limited to 'src/floatfns.c')
-rw-r--r--src/floatfns.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/floatfns.c b/src/floatfns.c
index 4c09036ac79..8534f1d04e4 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -147,7 +147,12 @@ DEFUN ("isnan", Fisnan, Sisnan, 1, 1, 0,
return isnan (XFLOAT_DATA (x)) ? Qt : Qnil;
}
-#ifdef HAVE_COPYSIGN
+/* Although the substitute does not work on NaNs, it is good enough
+ for platforms lacking the signbit macro. */
+#ifndef signbit
+# define signbit(x) ((x) < 0 || (IEEE_FLOATING_POINT && !(x) && 1 / (x) < 0))
+#endif
+
DEFUN ("copysign", Fcopysign, Scopysign, 2, 2, 0,
doc: /* Copy sign of X2 to value of X1, and return the result.
Cause an error if X1 or X2 is not a float. */)
@@ -161,9 +166,10 @@ Cause an error if X1 or X2 is not a float. */)
f1 = XFLOAT_DATA (x1);
f2 = XFLOAT_DATA (x2);
- return make_float (copysign (f1, f2));
+ /* Use signbit instead of copysign, to avoid calling make_float when
+ the result is X1. */
+ return signbit (f1) != signbit (f2) ? make_float (-f1) : x1;
}
-#endif
DEFUN ("frexp", Ffrexp, Sfrexp, 1, 1, 0,
doc: /* Get significand and exponent of a floating point number.
@@ -552,9 +558,7 @@ syms_of_floatfns (void)
defsubr (&Ssin);
defsubr (&Stan);
defsubr (&Sisnan);
-#ifdef HAVE_COPYSIGN
defsubr (&Scopysign);
-#endif
defsubr (&Sfrexp);
defsubr (&Sldexp);
defsubr (&Sfceiling);