|
15 | 15 | ival-hypot) |
16 | 16 |
|
17 | 17 | ;; Endpoint computation for both `add`, `sub`, and `hypot` (which has an add inside) |
18 | | -(define (eplinear bffn a-endpoint b-endpoint) |
19 | | - (match-define (endpoint a a!) a-endpoint) |
20 | | - (match-define (endpoint b b!) b-endpoint) |
| 18 | +(define (eplinear bffn a a! b b!) |
21 | 19 | (define-values (val exact?) (bf-return-exact? bffn (list a b))) |
22 | | - (endpoint val (or (and a! b! exact?) (and a! (bfinfinite? a)) (and b! (bfinfinite? b))))) |
| 20 | + (values val (or (and a! b! exact?) (and a! (bfinfinite? a)) (and b! (bfinfinite? b))))) |
23 | 21 |
|
24 | | -(define (eplinear! out mpfr-fn! a-endpoint b-endpoint rnd) |
25 | | - (match-define (endpoint a a!) a-endpoint) |
26 | | - (match-define (endpoint b b!) b-endpoint) |
| 22 | +(define (eplinear! out mpfr-fn! a a! b b! rnd) |
27 | 23 | (mpfr-set-prec! out (bf-precision)) |
28 | 24 | (define exact? (= 0 (mpfr-fn! out a b rnd))) |
29 | | - (endpoint out (or (and a! b! exact?) (and a! (bfinfinite? a)) (and b! (bfinfinite? b))))) |
| 25 | + (values out (or (and a! b! exact?) (and a! (bfinfinite? a)) (and b! (bfinfinite? b))))) |
30 | 26 |
|
31 | 27 | (define (ival-add! out x y) |
32 | | - (ival (eplinear! (ival-lo-val out) mpfr-add! (ival-lo x) (ival-lo y) 'down) |
33 | | - (eplinear! (ival-hi-val out) mpfr-add! (ival-hi x) (ival-hi y) 'up) |
| 28 | + (define-values (lo-val lo-imm?) (eplinear! (ival-lo-val out) mpfr-add! (ival-lo-val x) (ival-lo-fixed? x) (ival-lo-val y) (ival-lo-fixed? y) 'down)) |
| 29 | + (define-values (hi-val hi-imm?) (eplinear! (ival-hi-val out) mpfr-add! (ival-hi-val x) (ival-hi-fixed? x) (ival-hi-val y) (ival-hi-fixed? y) 'up)) |
| 30 | + (ival (endpoint lo-val lo-imm?) |
| 31 | + (endpoint hi-val hi-imm?) |
34 | 32 | (or (ival-err? x) (ival-err? y)) |
35 | 33 | (or (ival-err x) (ival-err y)))) |
36 | 34 |
|
37 | 35 | (define (ival-add x y) |
38 | 36 | (ival-add! (new-ival) x y)) |
39 | 37 |
|
40 | 38 | (define (ival-sub! out x y) |
41 | | - (ival (eplinear! (ival-lo-val out) mpfr-sub! (ival-lo x) (ival-hi y) 'down) |
42 | | - (eplinear! (ival-hi-val out) mpfr-sub! (ival-hi x) (ival-lo y) 'up) |
| 39 | + (define-values (lo-val lo-imm?) (eplinear! (ival-lo-val out) mpfr-sub! (ival-lo-val x) (ival-lo-fixed? x) (ival-hi-val y) (ival-hi-fixed? y) 'down)) |
| 40 | + (define-values (hi-val hi-imm?) (eplinear! (ival-hi-val out) mpfr-sub! (ival-hi-val x) (ival-hi-fixed? x) (ival-lo-val y) (ival-lo-fixed? y) 'up)) |
| 41 | + (ival (endpoint lo-val lo-imm?) |
| 42 | + (endpoint hi-val hi-imm?) |
43 | 43 | (or (ival-err? x) (ival-err? y)) |
44 | 44 | (or (ival-err x) (ival-err y)))) |
45 | 45 |
|
|
158 | 158 | (define err (or (ival-err x) (ival-err y))) |
159 | 159 | (define x* (ival-exact-fabs x)) |
160 | 160 | (define y* (ival-exact-fabs y)) |
161 | | - (ival (rnd 'down eplinear bfhypot (ival-lo x*) (ival-lo y*)) |
162 | | - (rnd 'up eplinear bfhypot (ival-hi x*) (ival-hi y*)) |
| 161 | + (define-values (lo-val lo-imm?) (rnd 'down eplinear bfhypot (ival-lo-val x*) (ival-lo-fixed? x*) (ival-lo-val y*) (ival-lo-fixed? y*))) |
| 162 | + (define-values (hi-val hi-imm?) (rnd 'up eplinear bfhypot (ival-hi-val x*) (ival-hi-fixed? x*) (ival-hi-val y*) (ival-hi-fixed? y*))) |
| 163 | + (ival (endpoint lo-val lo-imm?) |
| 164 | + (endpoint hi-val hi-imm?) |
163 | 165 | err? |
164 | 166 | err)) |
0 commit comments