diff options
author | Mark H Weaver <mhw@netris.org> | 2018-05-27 22:04:27 -0400 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2018-08-07 12:02:16 +0200 |
commit | fe92bc26a67c3092b64851cef06ab5a072bd705b (patch) | |
tree | 0ad2d731e71cc4375c30ec4e572b435e22a92409 | |
parent | c6f6edcc5002d4569db71fa4ce3d2c1b5da0577f (diff) | |
download | guile-fe92bc26a67c3092b64851cef06ab5a072bd705b.tar.gz |
Avoid inexact arithmetic in the type inferrer for 'sqrt'.
* module/language/cps/types.scm: Use 'exact-integer-sqrt' and avoid
inexact arithmetic in the range analysis of the type inferrer for
'sqrt'.
-rw-r--r-- | module/language/cps/types.scm | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/module/language/cps/types.scm b/module/language/cps/types.scm index b40e48c6f..bac25cf20 100644 --- a/module/language/cps/types.scm +++ b/module/language/cps/types.scm @@ -1668,13 +1668,16 @@ where (A0 <= A <= A1) and (B0 <= B <= B1)." (define-type-inferrer (sqrt x result) (let ((type (&type x))) (cond - ((and (zero? (logand type &complex)) (<= 0 (&min x))) + ((and (zero? (logand type &complex)) + (non-negative? (&min x))) (define! result (logior type &flonum) - (inexact->exact (floor (sqrt (&min x)))) + (exact-integer-sqrt (&min x)) (if (inf? (&max x)) +inf.0 - (inexact->exact (ceiling (sqrt (&max x))))))) + (call-with-values (lambda () (exact-integer-sqrt (&max x))) + (lambda (s r) + (if (zero? r) s (+ s 1))))))) (else (define! result (logior type &flonum &complex) -inf.0 +inf.0))))) |