bug-gnulib
[Top][All Lists]
Advanced

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

ldexpl: use fpucw


From: Bruno Haible
Subject: ldexpl: use fpucw
Date: Fri, 30 Mar 2007 02:18:21 +0200
User-agent: KMail/1.5.4

In case the ldexpl replacement is needed on an i386 platform (it will be
needed e.g. on NetBSD/i386), it needs to fpu control word twiddling.

Also, a small optim: The last squaring of 'factor' is not needed.


2007-03-29  Bruno Haible  <address@hidden>

        * lib/ldexpl.c: Include fpucw.h.
        (ldexpl): Use BEGIN/END_LONG_DOUBLE_ROUNDING. Skip the last unneeded
        multiplication.

*** lib/ldexpl.c        26 Mar 2007 22:26:05 -0000      1.6
--- lib/ldexpl.c        30 Mar 2007 00:15:08 -0000
***************
*** 25,30 ****
--- 25,31 ----
  #include <math.h>
  
  #include <float.h>
+ #include "fpucw.h"
  #include "isnanl.h"
  
  long double
***************
*** 32,53 ****
  {
    long double factor;
    int bit;
  
!   /* Check for zero, nan and infinity. */
!   if (isnanl (x) || x + x == x)
!     return x;
  
!   if (exp < 0)
      {
!       exp = -exp;
!       factor = 0.5L;
      }
-   else
-     factor = 2.0L;
  
!   for (bit = 1; bit <= exp; bit <<= 1, factor *= factor)
!     if (exp & bit)
!       x *= factor;
  
    return x;
  }
--- 33,68 ----
  {
    long double factor;
    int bit;
+   DECL_LONG_DOUBLE_ROUNDING
  
!   BEGIN_LONG_DOUBLE_ROUNDING ();
  
!   /* Check for zero, nan and infinity. */
!   if (!(isnanl (x) || x + x == x))
      {
!       if (exp < 0)
!       {
!         exp = -exp;
!         factor = 0.5L;
!       }
!       else
!       factor = 2.0L;
! 
!       if (exp > 0)
!       for (bit = 1;;)
!         {
!           /* Invariant: Here bit = 2^i, factor = 2^-2^i or = 2^2^i,
!              and bit <= exp.  */ 
!           if (exp & bit)
!             x *= factor;
!           bit <<= 1;
!           if (bit > exp)
!             break;
!           factor = factor * factor;
!         }
      }
  
!   END_LONG_DOUBLE_ROUNDING ();
  
    return x;
  }
Index: modules/ldexpl
===================================================================
RCS file: /sources/gnulib/gnulib/modules/ldexpl,v
retrieving revision 1.1
diff -c -3 -r1.1 ldexpl
*** modules/ldexpl      30 Mar 2007 00:13:24 -0000      1.1
--- modules/ldexpl      30 Mar 2007 00:15:08 -0000
***************
*** 8,13 ****
--- 8,14 ----
  Depends-on:
  math
  isnanl-nolibm
+ fpucw
  
  configure.ac:
  gl_FUNC_LDEXPL





reply via email to

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