Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range reduction fix2 #22

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -537,51 +537,51 @@
(define lo* (+ (bigfloat-exponent xlo) (bigfloat-precision xlo)))
(define hi* (+ (bigfloat-exponent xhi) (bigfloat-precision xhi)))

(if (<= lo* 0) ; if lo* belongs to (-1, 1)
(if (<= hi* 0) ; if hi* belongs to (-1, 1)
; -9223372036854775807 is a code for 0.bf, otherwise -9220000000000000000 and lower is a nan/inf
(if (or (and (< 1073741822 (abs lo*)) (not (equal? -9223372036854775807 lo*)))
(and (< 1073741822 (abs hi*)) (not (equal? -9223372036854775807 hi*))))
'too-wide ; interval includes inf/nan/overflow
'near-0)
(cond
[(equal? period 'pi)
(if (>= hi* 2) ; if hi* belongs to (-inf, -2] U [2, +inf)
'too-wide
'range-reduce)]
[(equal? period '2pi)
(if (>= hi* 4) ; if hi* belongs to (-inf, -8] U [8, +inf)
'too-wide
'range-reduce)]))
(if (<= lo* 1) ; if lo* belongs to (-2, 2)
(cond
[(equal? period 'pi)
(if (>= hi* 4) ; if hi* belongs to (-inf, -8] U [8, +inf)
'too-wide
'range-reduce)]
[(equal? period '2pi)
(if (>= hi* 5) ; if hi* belongs to (-inf, -16] U [16, +inf)
'too-wide
'range-reduce)])
(if (<= lo* 2) ; if lo* belongs to (-4, 4)

(if (or (and (< 1073741822 (abs lo*)) (not (equal? -9223372036854775807 lo*))) ; -9223372036854775807 is a code for 0.bf
(and (< 1073741822 (abs hi*)) (not (equal? -9223372036854775807 hi*)))) ; |lo* or hi*| > 1073741822 is nan/inf/overflow
'too-wide ; overflow/inf/nan
(if (<= lo* 0) ; if lo* belongs to (-1, 1)
(if (<= hi* 0) ; if hi* belongs to (-1, 1)
'near-0
(cond
[(equal? period 'pi)
(if (>= hi* 2) ; if hi* belongs to (-inf, -2] U [2, +inf)
'too-wide
'range-reduce)]
[(equal? period '2pi)
(if (>= hi* 4) ; if hi* belongs to (-inf, -8] U [8, +inf)
'too-wide
'range-reduce)]))
(if (<= lo* 1) ; if lo* belongs to (-2, 2)
(cond
[(equal? period 'pi)
(if (>= hi* 4) ; if hi* belongs to (-inf, -8] U [8, +inf)
(if (>= hi* 4) ; if hi* belongs to (-inf, -8] U [8, +inf)
'too-wide
'range-reduce)]
[(equal? period '2pi)
(if (>= hi* 5) ; if hi* belongs to (-inf, -16] U [16, +inf)
(if (>= hi* 5) ; if hi* belongs to (-inf, -16] U [16, +inf)
'too-wide
'range-reduce)])
(if (>= lo* 3) ; if lo* belongs to (-inf, -4] U [4, +inf)
(if (>= hi* 3) ; if hi* belongs to (-inf, -4] U [4, +inf)
(if (> (abs (- hi* lo*)) 1)
'too-wide
(if (equal? (bigfloat-signbit xlo) (bigfloat-signbit xhi))
'range-reduce
'too-wide))
'range-reduce)
'range-reduce)))))
(if (<= lo* 2) ; if lo* belongs to (-4, 4)
(cond
[(equal? period 'pi)
(if (>= hi* 4) ; if hi* belongs to (-inf, -8] U [8, +inf)
'too-wide
'range-reduce)]
[(equal? period '2pi)
(if (>= hi* 5) ; if hi* belongs to (-inf, -16] U [16, +inf)
'too-wide
'range-reduce)])
(if (>= lo* 3) ; if lo* belongs to (-inf, -4] U [4, +inf)
(if (>= hi* 3) ; if hi* belongs to (-inf, -4] U [4, +inf)
(if (> (abs (- hi* lo*)) 1)
'too-wide
(if (equal? (bigfloat-signbit xlo) (bigfloat-signbit xhi))
'range-reduce
'too-wide))
'range-reduce)
'range-reduce))))))

(define (ival-cos x)
(match-define (ival (endpoint xlo xlo!) (endpoint xhi xhi!) xerr? xerr) x)
Expand Down
Loading