emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 14af339: Define copysign on all platforms


From: Paul Eggert
Subject: [Emacs-diffs] master 14af339: Define copysign on all platforms
Date: Tue, 7 Mar 2017 11:32:09 -0500 (EST)

branch: master
commit 14af3395e6d8a2a95268138355ade408743922ac
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    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.
---
 admin/CPP-DEFINES |  1 -
 configure.ac      |  2 +-
 src/floatfns.c    | 14 +++++++++-----
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES
index 487c150..cead305 100644
--- a/admin/CPP-DEFINES
+++ b/admin/CPP-DEFINES
@@ -113,7 +113,6 @@ HAVE_CLOCK_GETTIME
 HAVE_CLOCK_SETTIME
 HAVE_COFF_H
 HAVE_COM_ERR_H
-HAVE_COPYSIGN
 HAVE_DBUS
 HAVE_DBUS_TYPE_IS_VALID
 HAVE_DBUS_VALIDATE_BUS_NAME
diff --git a/configure.ac b/configure.ac
index 6926076..ba944e6c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3888,7 +3888,7 @@ pthread_sigmask strsignal setitimer \
 sendto recvfrom getsockname getifaddrs freeifaddrs \
 gai_strerror sync \
 getpwent endpwent getgrent endgrent \
-cfmakeraw cfsetspeed copysign __executable_start log2 prctl)
+cfmakeraw cfsetspeed __executable_start log2 prctl)
 LIBS=$OLD_LIBS
 
 dnl No need to check for posix_memalign if aligned_alloc works.
diff --git a/src/floatfns.c b/src/floatfns.c
index 4c09036..8534f1d 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);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]