summaryrefslogtreecommitdiff
path: root/src/floatfns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/floatfns.c')
-rw-r--r--src/floatfns.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/floatfns.c b/src/floatfns.c
index aadae4fd9d6..f52dae47193 100644
--- a/src/floatfns.c
+++ b/src/floatfns.c
@@ -347,6 +347,21 @@ int
double_integer_scale (double d)
{
int exponent = ilogb (d);
+#ifdef HAIKU
+ /* On Haiku, the values returned by ilogb are nonsensical when
+ confronted with tiny numbers, inf, or NaN, which breaks the trick
+ used by code on other platforms, so we have to test for each case
+ manually, and return the appropriate value. */
+ if (exponent == FP_ILOGB0)
+ {
+ if (isnan (d))
+ return (DBL_MANT_DIG - DBL_MIN_EXP) + 2;
+ if (isinf (d))
+ return (DBL_MANT_DIG - DBL_MIN_EXP) + 1;
+
+ return (DBL_MANT_DIG - DBL_MIN_EXP);
+ }
+#endif
return (DBL_MIN_EXP - 1 <= exponent && exponent < INT_MAX
? DBL_MANT_DIG - 1 - exponent
: (DBL_MANT_DIG - DBL_MIN_EXP