summaryrefslogtreecommitdiff
path: root/src/floatfns.c
diff options
context:
space:
mode:
authorKarl Heuer <kwzh@gnu.org>1994-03-15 03:16:05 +0000
committerKarl Heuer <kwzh@gnu.org>1994-03-15 03:16:05 +0000
commit2983a4ebea3c8e24f7e799e920ecb5fd302639f0 (patch)
treeaff19830c0b553f2822c9b48a407ec1ffd194810 /src/floatfns.c
parentec1d130a28c2a4fb6febf2aad8434ad8cce4f7f6 (diff)
downloademacs-2983a4ebea3c8e24f7e799e920ecb5fd302639f0.tar.gz
(Flogb): Check for 0.0. Emulate logb if needed.
Diffstat (limited to 'src/floatfns.c')
-rw-r--r--src/floatfns.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/floatfns.c b/src/floatfns.c
index 27f8d084c03..81a42603b6a 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -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;
}