]> Savannah Git Hosting - gnulib.git/commitdiff
ldexp: port to non-two’s complement
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 21 Aug 2023 00:55:03 +0000 (17:55 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 21 Aug 2023 00:55:37 +0000 (17:55 -0700)
* lib/ldexp.c (FUNC): Don’t assume two’s-complement.

ChangeLog
lib/ldexp.c

index 6575ee12b6301bd52f5d3d591184e15c4b4f28a4..8f346acff5b077e80a0f34a4be7b9a13ff0ffb57 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-08-20  Paul Eggert  <eggert@cs.ucla.edu>
+
+       ldexp: port to non-two’s complement
+       * lib/ldexp.c (FUNC): Don’t assume two’s-complement.
+
 2023-08-20  Bruno Haible  <bruno@clisp.org>
 
        readutmp, boot-time: Fix the result on runit and s6 init systems.
index 844fd11f534f9e6f0850acc5802e355cff4c62fe..8bc4073527c433f0145efdc507ba772b13d2b7db 100644 (file)
@@ -57,16 +57,15 @@ FUNC (DOUBLE x, int exp)
   BEGIN_ROUNDING ();
 
   /* Check for zero, nan and infinity. */
-  if (!(ISNAN (x) || x + x == x || exp == 0))
+  if (!(ISNAN (x) || x + x == x))
     {
-      bool negexp = exp < 0;
-      DOUBLE factor = negexp ? L_(0.5) : L_(2.0);
+      DOUBLE factor = exp < 0 ? L_(0.5) : L_(2.0);
 
       while (true)
         {
-          if (exp & 1)
+          if (exp % 2 != 0)
             x *= factor;
-          exp = (exp + negexp) >> 1;
+          exp /= 2;
           if (exp == 0)
             break;
           factor = factor * factor;