mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 01:30:27 +02:00
Fix rounding in scm_i_divide2double for negative arguments.
* libguile/numbers.c (INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE): New macro. (scm_i_divide2double): Use INUM_LOSSLESSLY_CONVERTIBLE_TO_DOUBLE to determine if our fast path is safe. Previously, negative arguments were not checked properly. * test-suite/tests/numbers.test (exact->inexact): Add tests.
This commit is contained in:
parent
7e8166f5bd
commit
4cc2e41cf7
2 changed files with 24 additions and 4 deletions
|
@ -4021,6 +4021,19 @@
|
|||
(let ((big (ash 1 4096)))
|
||||
(= 1.0 (exact->inexact (/ (1+ big) big)))))
|
||||
|
||||
;; In guile 2.0.9, 'exact->inexact' guaranteed proper rounding when
|
||||
;; applied to non-negative fractions, but on 64-bit systems would
|
||||
;; sometimes double-round when applied to negative fractions,
|
||||
;; specifically when the numerator was a fixnum not exactly
|
||||
;; representable as a double.
|
||||
(with-test-prefix "frac inum/inum, numerator not exactly representable as a double"
|
||||
(let ((n (+ 1 (expt 2 dbl-mant-dig))))
|
||||
(for-each (lambda (d)
|
||||
(test (/ n d)
|
||||
(/ n d)
|
||||
(exact->inexact (/ n d))))
|
||||
'(3 5 6 7 9 11 13 17 19 23 0.0 -0.0 +nan.0 +inf.0 -inf.0))))
|
||||
|
||||
(test "round up to odd"
|
||||
;; =====================================================
|
||||
;; 11111111111111111111111111111111111111111111111111000101 ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue