Skip to content

Commit bcda3ea

Browse files
committed
Rollback ival-exact + fix tunnel vision changes
1 parent d90b6cf commit bcda3ea

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

ops/arith.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@
161161
(define (ival-hypot! out x y)
162162
(define err? (or (ival-err? x) (ival-err? y)))
163163
(define err (or (ival-err x) (ival-err y)))
164-
(define x* (ival-fabs x))
165-
(define y* (ival-fabs y))
164+
(define x* (ival-exact-fabs x))
165+
(define y* (ival-exact-fabs y))
166166
(ival (eplinear! (ival-lo-val out) mpfr-hypot! (ival-lo x*) (ival-lo y*) 'down)
167167
(eplinear! (ival-hi-val out) mpfr-hypot! (ival-hi x*) (ival-hi y*) 'up)
168168
err?

ops/core.rkt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
epfn
1818
split-ival
1919
ival-max-prec
20+
ival-exact-neg
21+
ival-exact-fabs
2022
bf-return-exact?
2123
ival-lo-fixed?
2224
ival-hi-fixed?
@@ -191,18 +193,14 @@
191193
(define (endpoint-min2 e1 e2 rnd)
192194
(match-define (endpoint x x!) e1)
193195
(match-define (endpoint y y!) e2)
194-
(define out
195-
(parameterize ([bf-precision (bf-precision)])
196-
(bf 0)))
196+
(define out (bf 0))
197197
(mpfr-min! out x y rnd)
198198
(endpoint out (or (and (bf=? out x) x!) (and (bf=? out y) y!))))
199199

200200
(define (endpoint-max2 e1 e2 rnd)
201201
(match-define (endpoint x x!) e1)
202202
(match-define (endpoint y y!) e2)
203-
(define out
204-
(parameterize ([bf-precision (bf-precision)])
205-
(bf 0)))
203+
(define out (bf 0))
206204
(mpfr-max! out x y rnd)
207205
(endpoint out (or (and (bf=? out x) x!) (and (bf=? out y) y!))))
208206

@@ -349,6 +347,14 @@
349347
(define (ival-max-prec x)
350348
(max (bigfloat-precision (ival-lo-val x)) (bigfloat-precision (ival-hi-val x))))
351349

350+
(define (ival-exact-fabs x)
351+
(parameterize ([bf-precision (ival-max-prec x)])
352+
(ival-fabs x)))
353+
354+
(define (ival-exact-neg x)
355+
(parameterize ([bf-precision (ival-max-prec x)])
356+
(ival-neg x)))
357+
352358
;; Since MPFR has a cap on exponents, no value can be more than twice MAX_VAL
353359
(define exp-overflow-threshold (bfadd (bflog (bfprev +inf.bf)) 1.bf))
354360
(define exp2-overflow-threshold (bfadd (bflog2 (bfprev +inf.bf)) 1.bf))
@@ -369,7 +375,7 @@
369375
(define* ival-log2 (compose (monotonic-mpfr mpfr-log2!) (clamp-strict 0.bf +inf.bf)))
370376
(define* ival-log10 (compose (monotonic-mpfr mpfr-log10!) (clamp-strict 0.bf +inf.bf)))
371377
(define* ival-log1p (compose (monotonic-mpfr mpfr-log1p!) (clamp-strict -1.bf +inf.bf)))
372-
[define* ival-logb (compose ival-floor ival-log2 ival-fabs)]
378+
[define* ival-logb (compose ival-floor ival-log2 ival-exact-fabs)]
373379

374380
(define* ival-sqrt (compose (monotonic-mpfr mpfr-sqrt!) (clamp 0.bf +inf.bf)))
375381
(define* ival-cbrt (monotonic-mpfr mpfr-cbrt!))
@@ -427,7 +433,7 @@
427433
(compose (overflows-at (monotonic-mpfr mpfr-cosh!)
428434
(bfneg acosh-overflow-threshold)
429435
acosh-overflow-threshold)
430-
ival-fabs))
436+
ival-exact-fabs))
431437
(define*
432438
ival-sinh
433439
(overflows-at (monotonic-mpfr mpfr-sinh!) (bfneg sinh-overflow-threshold) sinh-overflow-threshold))

ops/fmod.rkt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
(and (bflte? (ival-lo-val y) 0.bf) (bfgte? (ival-hi-val y) 0.bf))))
6464
(define err
6565
(or (ival-err x) (ival-err y) (and (bf=? (ival-lo-val y) 0.bf) (bf=? (ival-hi-val y) 0.bf))))
66-
(define y* (ival-fabs y))
66+
(define y* (ival-exact-fabs y))
6767
(cond
68-
[(= (mpfr-sign (ival-hi-val x)) -1) (ival-neg (ival-fmod-pos (ival-neg x) y* err? err))]
68+
[(= (mpfr-sign (ival-hi-val x)) -1) (ival-neg (ival-fmod-pos (ival-exact-neg x) y* err? err))]
6969
[(= (mpfr-sign (ival-lo-val x)) 1) (ival-fmod-pos x y* err? err)]
7070
[else
7171
(define-values (neg pos) (split-ival x 0.bf))
7272
(ival-union (ival-fmod-pos pos y* err? err)
73-
(ival-neg (ival-fmod-pos (ival-neg neg) y* err? err)))]))
73+
(ival-neg (ival-fmod-pos (ival-exact-neg neg) y* err? err)))]))
7474

7575
(define (ival-remainder-pos x y err? err)
7676
;; Assumes both `x` and `y` are entirely positive
@@ -106,11 +106,12 @@
106106
(and (bflte? (ival-lo-val y) 0.bf) (bfgte? (ival-hi-val y) 0.bf))))
107107
(define err
108108
(or (ival-err x) (ival-err y) (and (bf=? (ival-lo-val y) 0.bf) (bf=? (ival-hi-val y) 0.bf))))
109-
(define y* (ival-fabs y))
109+
(define y* (ival-exact-fabs y))
110110
(cond
111-
[(= (mpfr-sign (ival-hi-val x)) -1) (ival-neg (ival-remainder-pos (ival-neg x) y* err? err))]
111+
[(= (mpfr-sign (ival-hi-val x)) -1)
112+
(ival-neg (ival-remainder-pos (ival-exact-neg x) y* err? err))]
112113
[(= (mpfr-sign (ival-lo-val x)) 1) (ival-remainder-pos x y* err? err)]
113114
[else
114115
(define-values (neg pos) (split-ival x 0.bf))
115116
(ival-union (ival-remainder-pos pos y* err? err)
116-
(ival-neg (ival-remainder-pos (ival-neg neg) y* err? err)))]))
117+
(ival-neg (ival-remainder-pos (ival-exact-neg neg) y* err? err)))]))

ops/pow.rkt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,17 @@
129129
; If y is an integer point interval, there's no error,
130130
; because it's always valid to raise to an integer power.
131131
(if (bfodd? (ival-lo-val y))
132-
(ival-neg (ival-pow-pos (ival-fabs x) y)) ; Use fabs in case of [x, 0]
133-
(ival-pow-pos (ival-fabs x) y))
132+
(ival-neg (ival-pow-pos (ival-exact-fabs x) y)) ; Use fabs in case of [x, 0]
133+
(ival-pow-pos (ival-exact-fabs x) y))
134134
; If y is non-integer point interval, it must be an even
135135
; fraction (because all bigfloats are) so we always error
136136
ival-illegal)
137137
; Moreover, if we have (-x)^y, that's basically x^y U -(x^y).
138-
(let ([pospow (ival-pow-pos (ival-fabs x) y)])
138+
(let ([pospow (ival-pow-pos (ival-exact-fabs x) y)])
139139
(ival-then (ival-assert ival-maybe) (ival-union (ival-neg pospow) pospow)))))
140140

141141
(define (ival-pow2 x)
142-
((monotonic->ival (lambda (x) (bfmul x x))) (ival-fabs x)))
142+
((monotonic->ival (lambda (x) (bfmul x x))) (ival-exact-fabs x)))
143143

144144
(define (ival-pow x y)
145145
(cond

0 commit comments

Comments
 (0)