bc: avoid bad floating-point roundoff in seconds->date

Thanks, Xsmith!

Closes #3489
This commit is contained in:
Matthew Flatt 2020-11-07 12:43:28 -07:00
parent 09c9901f6b
commit 7c8d9c6523
2 changed files with 8 additions and 0 deletions

View File

@ -128,4 +128,10 @@
(err/rt-test (seconds->date (expt 2 50)) out-of-range)
(err/rt-test (seconds->date (expt 2 60)) out-of-range)))
;; Check inexact arithmetic
(test (seconds->date 0 #f)
seconds->date 0.1e-16 #f)
(test (date* 59 59 23 31 12 1969 3 364 #f 0 999999999 "UTC")
seconds->date -0.1e-16 #f)
(report-errs)

View File

@ -9790,6 +9790,8 @@ static Scheme_Object *seconds_to_date(int argc, Scheme_Object **argv)
if (SCHEME_INTP(secs) || SCHEME_BIGNUMP(secs)) {
nsecs = scheme_make_integer(0);
} else {
p[0] = secs;
secs = scheme_inexact_to_exact(1, p);
nsecs = secs;
p[0] = secs;
secs = scheme_floor(1, p);