Generalize reporting of wasted precision to arbitrary exact arithmetic expressions.

This commit is contained in:
Vincent St-Amour 2011-05-16 18:31:37 -04:00
parent ec696f26ae
commit 2a4a4e8184
2 changed files with 9 additions and 2 deletions

View File

@ -1,8 +1,11 @@
#;
(
precision-loss.rkt 13:3 (#%app * (quote 3/4) (quote 2/3)) -- exact arithmetic subexpression inside a float expression, extra precision discarded -- caused by: 13:0 (#%app + (#%app * (quote 3/4) (quote 2/3)) (quote 2.0))
precision-loss.rkt 16:3 (#%app * (quote 3/4) (quote 2/3)) -- exact arithmetic subexpression inside a float expression, extra precision discarded -- caused by: 16:0 (#%app + (#%app * (quote 3/4) (quote 2/3)) (quote 2.0))
precision-loss.rkt 20:3 (#%app - (quote 3/4)) -- exact arithmetic subexpression inside a float expression, extra precision discarded -- caused by: 20:0 (#%app + (#%app - (quote 3/4)) (quote 2.0))
2.5
2.75
1.25
2.5
)
#lang typed/racket
@ -14,3 +17,7 @@ precision-loss.rkt 13:3 (#%app * (quote 3/4) (quote 2/3)) -- exact arithmetic su
2.0) ; extra precision lost
(+ 3/4 2.0) ; here, since the exact subexpression is atomic, it will get
;; coerced anyway, so there's not much need for a warning
(+ (- 3/4) ; should work on unary exprs too
2.0)
(+ (vector-ref '#(2/3 1/2 3/4) (assert (+ 1/4 3/4) exact-integer?)) ; and this is not an arith expr
2.0)

View File

@ -117,7 +117,7 @@
;; be coerced anyway, or about things like:
;; (vector-ref vector-of-rationals x)
;; which don't perform arithmetic despite returning numbers.
[(#%plain-app (~var op (float-op binary-float-ops)) xs ...)
[e:arith-expr
(log-close-call
"exact arithmetic subexpression inside a float expression, extra precision discarded"
subexpr this-syntax)]