Commit 6694b327 authored by Karl Heuer's avatar Karl Heuer
Browse files

(Flogb): Check for 0.0. Emulate logb if needed.

parent c2d606f4
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment