changeset 6359:800c035273e9

(Flogb): Check for 0.0. Emulate logb if needed.
author Karl Heuer <kwzh@gnu.org>
date Tue, 15 Mar 1994 03:16:05 +0000
parents 250e69a75938
children 4cab647064a8
files src/floatfns.c
diffstat 1 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/floatfns.c	Tue Mar 15 02:52:55 1994 +0000
+++ b/src/floatfns.c	Tue Mar 15 03:16:05 1994 +0000
@@ -656,23 +656,40 @@
   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;
 }