]> code.delx.au - gnu-emacs/commitdiff
(Flogb): Check for 0.0. Emulate logb if needed.
authorKarl Heuer <kwzh@gnu.org>
Tue, 15 Mar 1994 03:16:05 +0000 (03:16 +0000)
committerKarl Heuer <kwzh@gnu.org>
Tue, 15 Mar 1994 03:16:05 +0000 (03:16 +0000)
src/floatfns.c

index 27f8d084c03bc74d7fa61a86692b4de6cc4e8ab8..81a42603b6ace3e5664d7b5d38475fcb541d8b9a 100644 (file)
@@ -656,23 +656,40 @@ This is the same as the exponent of a float.")
   int value;
   double f = extract_float (arg);
 
+  if (f == 0.0)
+    value = -(VALMASK >> 1);
+  else
+    {
 #ifdef HAVE_LOGB
-  IN_FLOAT (value = logb (f), "logb", arg);
-  XSET (val, Lisp_Int, value);
+      IN_FLOAT (value = logb (f), "logb", arg);
 #else
 #ifdef HAVE_FREXP
-  {
-    int exp;  
-
-    IN_FLOAT (frexp (f, &exp), "logb", arg);
-    XSET (val, Lisp_Int, exp-1);
-  }
+      IN_FLOAT (frexp (f, &value), "logb", arg);
+      value--;
 #else
-  /* Would someone like to write code to emulate logb?  */
-  error ("`logb' not implemented on this operating system");
+      int i;
+      double d;
+      if (f < 0.0)
+       f = -f;
+      value = -1;
+      while (f < 0.5)
+       {
+         for (i = 1, d = 0.5; d * d >= f; i += i)
+           d *= d;
+         f /= d;
+         value -= i;
+       }
+      while (f >= 1.0)
+       {
+         for (i = 1, d = 2.0; d * d <= f; i += i)
+           d *= d;
+         f /= d;
+         value += i;
+       }
 #endif
 #endif
-
+    }
+  XSET (val, Lisp_Int, value);
   return val;
 }