diff options
Diffstat (limited to 'src/floatfns.c')
| -rw-r--r-- | src/floatfns.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/floatfns.c b/src/floatfns.c index 3199d572138..7e77dbd16dc 100644 --- a/src/floatfns.c +++ b/src/floatfns.c | |||
| @@ -348,6 +348,29 @@ integer_value (Lisp_Object a) | |||
| 348 | return true; | 348 | return true; |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | /* Return the integer exponent E such that D * FLT_RADIX**E (i.e., | ||
| 352 | scalbn (D, E)) is an integer that has precision equal to D and is | ||
| 353 | representable as a double. | ||
| 354 | |||
| 355 | Return DBL_MANT_DIG - DBL_MIN_EXP (the maximum possible valid | ||
| 356 | scale) if D is zero or tiny. Return a value greater than | ||
| 357 | DBL_MANT_DIG - DBL_MIN_EXP if there is conversion trouble; on all | ||
| 358 | current platforms this can happen only if D is infinite or a NaN. */ | ||
| 359 | |||
| 360 | int | ||
| 361 | double_integer_scale (double d) | ||
| 362 | { | ||
| 363 | int exponent = ilogb (d); | ||
| 364 | return (DBL_MIN_EXP - 1 <= exponent && exponent < INT_MAX | ||
| 365 | ? DBL_MANT_DIG - 1 - exponent | ||
| 366 | : (DBL_MANT_DIG - DBL_MIN_EXP | ||
| 367 | + (exponent == INT_MAX | ||
| 368 | || (exponent == FP_ILOGBNAN | ||
| 369 | && (FP_ILOGBNAN != FP_ILOGB0 || isnan (d))) | ||
| 370 | || (!IEEE_FLOATING_POINT && exponent == INT_MIN | ||
| 371 | && (FP_ILOGB0 != INT_MIN || d != 0))))); | ||
| 372 | } | ||
| 373 | |||
| 351 | /* the rounding functions */ | 374 | /* the rounding functions */ |
| 352 | 375 | ||
| 353 | static Lisp_Object | 376 | static Lisp_Object |