Skip to content

Commit 89bc895

Browse files
committed
Merge branch 'main' into codex/inline-epfn-for-boolean-functions
2 parents 5b6b6c6 + ec901a6 commit 89bc895

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

ops/arith.rkt

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,31 @@
1616
ival-hypot)
1717

1818
;; Endpoint computation for both `add`, `sub`, and `hypot` (which has an add inside)
19-
(define (eplinear bffn a-endpoint b-endpoint)
20-
(match-define (endpoint a a!) a-endpoint)
21-
(match-define (endpoint b b!) b-endpoint)
19+
(define (eplinear bffn a a! b b!)
2220
(define-values (val exact?) (bf-return-exact? bffn (list a b)))
23-
(endpoint val (or (and a! b! exact?) (and a! (bfinfinite? a)) (and b! (bfinfinite? b)))))
21+
(values val (or (and a! b! exact?) (and a! (bfinfinite? a)) (and b! (bfinfinite? b)))))
2422

25-
(define (eplinear! out mpfr-fn! a-endpoint b-endpoint rnd)
26-
(match-define (endpoint a a!) a-endpoint)
27-
(match-define (endpoint b b!) b-endpoint)
23+
(define (eplinear! out mpfr-fn! a a! b b! rnd)
2824
(mpfr-set-prec! out (bf-precision))
2925
(define exact? (= 0 (mpfr-fn! out a b rnd)))
30-
(endpoint out (or (and a! b! exact?) (and a! (bfinfinite? a)) (and b! (bfinfinite? b)))))
26+
(values out (or (and a! b! exact?) (and a! (bfinfinite? a)) (and b! (bfinfinite? b)))))
3127

3228
(define (ival-add! out x y)
33-
(ival (eplinear! (ival-lo-val out) mpfr-add! (ival-lo x) (ival-lo y) 'down)
34-
(eplinear! (ival-hi-val out) mpfr-add! (ival-hi x) (ival-hi y) 'up)
35-
(or (ival-err? x) (ival-err? y))
36-
(or (ival-err x) (ival-err y))))
29+
(match-define (ival (endpoint xlo xlo!) (endpoint xhi xhi!) xerr? xerr) x)
30+
(match-define (ival (endpoint ylo ylo!) (endpoint yhi yhi!) yerr? yerr) y)
31+
(define-values (lo lo!) (eplinear! (ival-lo-val out) mpfr-add! xlo xlo! ylo ylo! 'down))
32+
(define-values (hi hi!) (eplinear! (ival-hi-val out) mpfr-add! xhi xhi! yhi yhi! 'up))
33+
(ival (endpoint lo lo!) (endpoint hi hi!) (or xerr? yerr?) (or xerr yerr)))
3734

3835
(define (ival-add x y)
3936
(ival-add! (new-ival (bf-precision)) x y))
4037

4138
(define (ival-sub! out x y)
42-
(ival (eplinear! (ival-lo-val out) mpfr-sub! (ival-lo x) (ival-hi y) 'down)
43-
(eplinear! (ival-hi-val out) mpfr-sub! (ival-hi x) (ival-lo y) 'up)
44-
(or (ival-err? x) (ival-err? y))
45-
(or (ival-err x) (ival-err y))))
39+
(match-define (ival (endpoint xlo xlo!) (endpoint xhi xhi!) xerr? xerr) x)
40+
(match-define (ival (endpoint ylo ylo!) (endpoint yhi yhi!) yerr? yerr) y)
41+
(define-values (lo lo!) (eplinear! (ival-lo-val out) mpfr-sub! xlo xlo! yhi yhi! 'down))
42+
(define-values (hi hi!) (eplinear! (ival-hi-val out) mpfr-sub! xhi xhi! ylo ylo! 'up))
43+
(ival (endpoint lo lo!) (endpoint hi hi!) (or xerr? yerr?) (or xerr yerr)))
4644

4745
(define (ival-sub x y)
4846
(ival-sub! (new-ival (bf-precision)) x y))
@@ -161,12 +159,11 @@
161159
(define (ival-hypot! out x y)
162160
(define err? (or (ival-err? x) (ival-err? y)))
163161
(define err (or (ival-err x) (ival-err y)))
164-
(define x* (ival-exact-fabs x))
165-
(define y* (ival-exact-fabs y))
166-
(ival (eplinear! (ival-lo-val out) mpfr-hypot! (ival-lo x*) (ival-lo y*) 'down)
167-
(eplinear! (ival-hi-val out) mpfr-hypot! (ival-hi x*) (ival-hi y*) 'up)
168-
err?
169-
err))
162+
(match-define (ival (endpoint xlo xlo!) (endpoint xhi xhi!) _ _) (ival-exact-fabs x))
163+
(match-define (ival (endpoint ylo ylo!) (endpoint yhi yhi!) _ _) (ival-exact-fabs y))
164+
(define-values (lo lo!) (eplinear! (ival-lo-val out) mpfr-hypot! xlo xlo! ylo ylo! 'down))
165+
(define-values (hi hi!) (eplinear! (ival-hi-val out) mpfr-hypot! xhi xhi! yhi yhi! 'up))
166+
(ival (endpoint lo lo!) (endpoint hi hi!) err? err))
170167

171168
(define (ival-hypot x y)
172169
(ival-hypot! (new-ival (bf-precision)) x y))

ops/pow.rkt

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@
1313
[(and (< (mpfr-exp (ival-hi-val x)) 1) (not (bfinfinite? (ival-hi-val x)))) -1]
1414
[else 0]))
1515

16-
(define (eppow a-endpoint b-endpoint a-class b-class)
17-
(match-define (endpoint a a!) a-endpoint)
18-
(match-define (endpoint b b!) b-endpoint)
16+
(define (eppow a a! b b! a-class b-class)
1917
(when (bfzero? a)
2018
(set! a 0.bf)) ; Handle (-0)^(-1)
2119
(define-values (val exact?) (bf-return-exact? bfexpt (list a b)))
22-
(endpoint val
23-
(or (and a! b! exact?)
24-
(and a! (bf=? a 1.bf))
25-
(and a! (bfzero? a) (not (= b-class 0)))
26-
(and a! (bfinfinite? a) (not (= b-class 0)))
27-
(and b! (bfzero? b))
28-
(and b! (bfinfinite? b) (not (= a-class 0))))))
20+
(values val
21+
(or (and a! b! exact?)
22+
(and a! (bf=? a 1.bf))
23+
(and a! (bfzero? a) (not (= b-class 0)))
24+
(and a! (bfinfinite? a) (not (= b-class 0)))
25+
(and b! (bfzero? b))
26+
(and b! (bfinfinite? b) (not (= a-class 0))))))
2927

3028
(define (ival-copy-movability i1 i2)
3129
(ival (endpoint (ival-lo-val i1) (ival-lo-fixed? i2))
@@ -41,8 +39,24 @@
4139
(define y-class (classify-ival y))
4240

4341
(define (mk-pow a b c d)
44-
(match-define (endpoint lo lo!) (rnd 'down eppow a b x-class y-class))
45-
(match-define (endpoint hi hi!) (rnd 'up eppow c d x-class y-class))
42+
(define-values (lo lo!)
43+
(rnd 'down
44+
eppow
45+
(endpoint-val a)
46+
(endpoint-immovable? a)
47+
(endpoint-val b)
48+
(endpoint-immovable? b)
49+
x-class
50+
y-class))
51+
(define-values (hi hi!)
52+
(rnd 'up
53+
eppow
54+
(endpoint-val c)
55+
(endpoint-immovable? c)
56+
(endpoint-val d)
57+
(endpoint-immovable? d)
58+
x-class
59+
y-class))
4660

4761
(define-values (real-lo! real-hi!)
4862
(cond

0 commit comments

Comments
 (0)