Skip to content

Commit 4e74d29

Browse files
authored
Merge pull request #109 from herbie-fp/fix-105
Fix near-underflows in `ival-pow`
2 parents 9afee49 + daf522b commit 4e74d29

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ops/pow.rkt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@
5252
(match-define (endpoint cval c!) c)
5353
(match-define (endpoint dval d!) d)
5454

55-
;; Important: exp2-overflow-threshold is an exact power of 2, so we can use >=
55+
;; Can't use >=, even though exp2-overflow-threshold is a
56+
;; power of 2, because mpfr-exp is offset by 1 from the real
57+
;; exponent, which matters when we add them.
5658
(define must-overflow
5759
(and (bfinfinite? hi)
5860
(= (* x-class y-class) 1)
59-
(>= (+ (mpfr-exp bval) (mpfr-exp (rnd 'zero bflog2 aval)))
60-
(mpfr-exp exp2-overflow-threshold))))
61+
(> (+ (mpfr-exp bval) (mpfr-exp (rnd 'zero bflog2 aval)))
62+
(mpfr-exp exp2-overflow-threshold))))
63+
6164
(define must-underflow
6265
(and (bfzero? lo)
6366
(= (* x-class y-class) -1)
64-
(>= (+ (mpfr-exp dval) (mpfr-exp (rnd 'zero bflog2 cval)))
65-
(mpfr-exp exp2-overflow-threshold))))
67+
(> (+ (mpfr-exp dval) (mpfr-exp (rnd 'zero bflog2 cval)))
68+
(mpfr-exp exp2-overflow-threshold))))
6669

6770
(define real-lo! (or lo! must-underflow (and (bfzero? lo) a! b!)))
6871
(define real-hi! (or hi! must-underflow must-overflow (and (bfinfinite? hi) c! d!)))

test.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
(require "main.rkt"
2222
"mpfr.rkt")
2323
(provide ival-valid?
24+
ival-refines?
2425
function-table
2526
sample-interval
2627
slow-tests

0 commit comments

Comments
 (0)