aboutsummaryrefslogtreecommitdiffstats
path: root/src/floatfns.c
diff options
context:
space:
mode:
authorPaul Eggert2019-11-10 15:06:49 -0800
committerPaul Eggert2019-11-13 13:10:08 -0800
commitff10e9517d98aa606e007d3aa4d5aef1c423ab77 (patch)
tree99d676a2ef88a024fdfd3fdafcdb7abb508e0f55 /src/floatfns.c
parent65fb04801c59ac204790e0a5c0599c9b11151f32 (diff)
downloademacs-ff10e9517d98aa606e007d3aa4d5aef1c423ab77.tar.gz
emacs-ff10e9517d98aa606e007d3aa4d5aef1c423ab77.zip
Refactor double integer scaling
This doesn’t alter behavior, and simplifies a future commit. * src/floatfns.c (double_integer_scale): New function, with body adapted from the old timefns.c. * src/timefns.c (decode_float_time): Use it.
Diffstat (limited to 'src/floatfns.c')
-rw-r--r--src/floatfns.c23
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
360int
361double_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
353static Lisp_Object 376static Lisp_Object