Skip to content

Commit c6667dc

Browse files
committed
Direct rounding for mul and div
1 parent 6f38311 commit c6667dc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ops/arith.rkt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
(define (ival-sub x y)
4747
(ival-sub! (new-ival) x y))
4848

49-
(define (epmul! out a-endpoint b-endpoint a-class b-class)
49+
(define (epmul! out a-endpoint b-endpoint a-class b-class rnd)
5050
(match-define (endpoint a a!) a-endpoint)
5151
(match-define (endpoint b b!) b-endpoint)
5252
(define a0 (bfzero? a))
@@ -57,7 +57,7 @@
5757
[(or a0 b0)
5858
(mpfr-set! out 0.bf 'nearest)
5959
#t]
60-
[else (= 0 (mpfr-mul! out a b (bf-rounding-mode)))]))
60+
[else (= 0 (mpfr-mul! out a b rnd))]))
6161
(endpoint out
6262
(or (and a! b! exact?)
6363
(and a! a0)
@@ -76,8 +76,8 @@
7676

7777
(define (mkmult out a b c d)
7878
(match-define (ival (endpoint rlo _) (endpoint rhi _) _ _) out)
79-
(ival (rnd 'down epmul! rlo a b x-sign y-sign)
80-
(rnd 'up epmul! rhi c d x-sign y-sign)
79+
(ival (epmul! rlo a b x-sign y-sign 'down)
80+
(epmul! rhi c d x-sign y-sign 'up)
8181
(or xerr? yerr?)
8282
(or xerr yerr)))
8383

@@ -102,11 +102,11 @@
102102
(mpfr-set! (ival-hi-val out) hi 'up) ; should be exact
103103
(ival (endpoint (ival-lo-val out) lo!) (endpoint (ival-hi-val out) hi!) err? err)]))
104104

105-
(define (epdiv! out a-endpoint b-endpoint a-class)
105+
(define (epdiv! out a-endpoint b-endpoint a-class rnd)
106106
(match-define (endpoint a a!) a-endpoint)
107107
(match-define (endpoint b b!) b-endpoint)
108108
(mpfr-set-prec! out (bf-precision))
109-
(define exact? (= 0 (mpfr-div! out a b (bf-rounding-mode))))
109+
(define exact? (= 0 (mpfr-div! out a b rnd)))
110110
(endpoint out
111111
(or (and a! b! exact?)
112112
(and a! (bfzero? a))
@@ -124,7 +124,7 @@
124124
(define y-class (classify-ival-strict y))
125125

126126
(define (mkdiv a b c d)
127-
(ival (rnd 'down epdiv! rlo a b x-class) (rnd 'up epdiv! rhi c d x-class) err? err))
127+
(ival (epdiv! rlo a b x-class 'down) (epdiv! rhi c d x-class 'up) err? err))
128128

129129
(match* (x-class y-class)
130130
[(_ 0) ; In this case, y stradles 0

0 commit comments

Comments
 (0)