fix round-to-even for exact->inexact
on rationals
Thanks again to Robby
This commit is contained in:
parent
ce7487182a
commit
5cb02282f5
|
@ -3286,6 +3286,16 @@
|
||||||
(arithmetic-shift (random (expt 2 24)) 24)
|
(arithmetic-shift (random (expt 2 24)) 24)
|
||||||
(random (expt 2 28)))))
|
(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)
|
;; exact->inexact precision (thanks to Neil Toronto)
|
||||||
|
|
||||||
|
|
|
@ -120,9 +120,9 @@ FP_TYPE SCHEME_RATIONAL_TO_FLOAT(const Scheme_Object *o)
|
||||||
} else {
|
} else {
|
||||||
/* Round to even: */
|
/* Round to even: */
|
||||||
a[0] = d;
|
a[0] = d;
|
||||||
if (!scheme_odd_p(1, a)) {
|
if (SCHEME_FALSEP(scheme_odd_p(1, a))) {
|
||||||
a[0] = n;
|
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));
|
n = scheme_bin_plus(n, scheme_make_integer(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user