fix round-to-even for exact->inexact on rationals

Thanks again to Robby
This commit is contained in:
Matthew Flatt 2015-11-22 18:09:11 -07:00
parent ce7487182a
commit 5cb02282f5
2 changed files with 13 additions and 3 deletions

View File

@ -3286,6 +3286,16 @@
(arithmetic-shift (random (expt 2 24)) 24)
(random (expt 2 28)))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check roun-to-even of rationale conversion (thanks to Robby)
(let ()
(define l (floating-point-bytes->real #"\x1a\xd8\x9c\x17\x21\x2e\xfd\x25" #t))
(define r (floating-point-bytes->real #"\x1a\xd8\x9c\x17\x21\x2e\xfd\x26" #t))
(test r exact->inexact (/ (+ (inexact->exact l)
(inexact->exact r))
2)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; exact->inexact precision (thanks to Neil Toronto)

View File

@ -104,7 +104,7 @@ FP_TYPE SCHEME_RATIONAL_TO_FLOAT(const Scheme_Object *o)
if (shift > FLOAT_M_BITS) {
shift = FLOAT_M_BITS;
}
a[0] = n;
a[1] = scheme_make_integer(shift);
n = scheme_bitwise_shift(2, a);
@ -120,9 +120,9 @@ FP_TYPE SCHEME_RATIONAL_TO_FLOAT(const Scheme_Object *o)
} else {
/* Round to even: */
a[0] = d;
if (!scheme_odd_p(1, a)) {
if (SCHEME_FALSEP(scheme_odd_p(1, a))) {
a[0] = n;
if (!scheme_even_p(1, a)) {
if (SCHEME_FALSEP(scheme_even_p(1, a))) {
n = scheme_bin_plus(n, scheme_make_integer(1));
}
}