diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2019-11-10 15:06:49 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2019-11-13 13:10:08 -0800 |
commit | ff10e9517d98aa606e007d3aa4d5aef1c423ab77 (patch) | |
tree | 99d676a2ef88a024fdfd3fdafcdb7abb508e0f55 /src/timefns.c | |
parent | 65fb04801c59ac204790e0a5c0599c9b11151f32 (diff) | |
download | emacs-ff10e9517d98aa606e007d3aa4d5aef1c423ab77.tar.gz |
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/timefns.c')
-rw-r--r-- | src/timefns.c | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/src/timefns.c b/src/timefns.c index fe08efd4c10..cf634a82b4e 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -406,26 +406,9 @@ decode_float_time (double t, struct lisp_time *result) } else { - int exponent = ilogb (t); - int scale; - if (exponent < DBL_MANT_DIG) - { - if (exponent < DBL_MIN_EXP - 1) - { - if (exponent == FP_ILOGBNAN - && (FP_ILOGBNAN != FP_ILOGB0 || isnan (t))) - return EINVAL; - /* T is tiny. SCALE must be less than FLT_RADIX_POWER_SIZE, - as otherwise T would be scaled as if it were normalized. */ - scale = flt_radix_power_size - 1; - } - else - { - /* The typical case. */ - scale = DBL_MANT_DIG - 1 - exponent; - } - } - else if (exponent < INT_MAX) + int scale = double_integer_scale (t); + + if (scale < 0) { /* T is finite but so large that HZ would be less than 1 if T's precision were represented exactly. SCALE must be @@ -435,8 +418,8 @@ decode_float_time (double t, struct lisp_time *result) which is typically better than signaling overflow. */ scale = 0; } - else - return FP_ILOGBNAN == INT_MAX && isnan (t) ? EINVAL : EOVERFLOW; + else if (flt_radix_power_size <= scale) + return isnan (t) ? EDOM : EOVERFLOW; double scaled = scalbn (t, scale); eassert (trunc (scaled) == scaled); |