Skip to content

Commit 31f8d8d

Browse files
authored
Merge branch 'main' into pre-fabs
2 parents 55d3c17 + 73d67df commit 31f8d8d

File tree

7 files changed

+259
-138
lines changed

7 files changed

+259
-138
lines changed

eval/compile.rkt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,37 @@
3535

3636
[(list 'if c y f) (list ival-if c y f)]
3737

38-
[(list 'neg x) (list ival-neg x)]
39-
[(list 'acos x) (list ival-acos x)]
40-
[(list 'acosh x) (list ival-acosh x)]
41-
[(list 'asin x) (list ival-asin x)]
42-
[(list 'asinh x) (list ival-asinh x)]
43-
[(list 'atan x) (list ival-atan x)]
44-
[(list 'atanh x) (list ival-atanh x)]
45-
[(list 'cbrt x) (list ival-cbrt x)]
38+
[(list 'neg x) (list ival-neg! (alloc-outreg!) x)]
39+
[(list 'acos x) (list ival-acos! (alloc-outreg!) x)]
40+
[(list 'acosh x) (list ival-acosh! (alloc-outreg!) x)]
41+
[(list 'asin x) (list ival-asin! (alloc-outreg!) x)]
42+
[(list 'asinh x) (list ival-asinh! (alloc-outreg!) x)]
43+
[(list 'atan x) (list ival-atan! (alloc-outreg!) x)]
44+
[(list 'atanh x) (list ival-atanh! (alloc-outreg!) x)]
45+
[(list 'cbrt x) (list ival-cbrt! (alloc-outreg!) x)]
4646
[(list 'ceil x) (list ival-ceil x)]
4747
[(list 'cos x) (list ival-cos x)]
48-
[(list 'cosh x) (list ival-cosh x)]
49-
[(list 'erf x) (list ival-erf x)]
50-
[(list 'erfc x) (list ival-erfc x)]
51-
[(list 'exp x) (list ival-exp x)]
52-
[(list 'exp2 x) (list ival-exp2 x)]
53-
[(list 'expm1 x) (list ival-expm1 x)]
48+
[(list 'cosh x) (list ival-cosh! (alloc-outreg!) x)]
49+
[(list 'erf x) (list ival-erf! (alloc-outreg!) x)]
50+
[(list 'erfc x) (list ival-erfc! (alloc-outreg!) x)]
51+
[(list 'exp x) (list ival-exp! (alloc-outreg!) x)]
52+
[(list 'exp2 x) (list ival-exp2! (alloc-outreg!) x)]
53+
[(list 'expm1 x) (list ival-expm1! (alloc-outreg!) x)]
5454
[(list 'fabs x) (list ival-fabs x)]
5555
[(list 'floor x) (list ival-floor x)]
5656
[(list 'lgamma x) (list ival-lgamma x)]
57-
[(list 'log x) (list ival-log x)]
58-
[(list 'log10 x) (list ival-log10 x)]
59-
[(list 'log1p x) (list ival-log1p x)]
60-
[(list 'log2 x) (list ival-log2 x)]
57+
[(list 'log x) (list ival-log! (alloc-outreg!) x)]
58+
[(list 'log10 x) (list ival-log10! (alloc-outreg!) x)]
59+
[(list 'log1p x) (list ival-log1p! (alloc-outreg!) x)]
60+
[(list 'log2 x) (list ival-log2! (alloc-outreg!) x)]
6161
[(list 'logb x) (list ival-logb x)]
62-
[(list 'rint x) (list ival-rint x)]
62+
[(list 'rint x) (list ival-rint! (alloc-outreg!) x)]
6363
[(list 'round x) (list ival-round x)]
6464
[(list 'sin x) (list ival-sin x)]
65-
[(list 'sinh x) (list ival-sinh x)]
66-
[(list 'sqrt x) (list ival-sqrt x)]
65+
[(list 'sinh x) (list ival-sinh! (alloc-outreg!) x)]
66+
[(list 'sqrt x) (list ival-sqrt! (alloc-outreg!) x)]
6767
[(list 'tan x) (list ival-tan x)]
68-
[(list 'tanh x) (list ival-tanh x)]
68+
[(list 'tanh x) (list ival-tanh! (alloc-outreg!) x)]
6969
[(list 'tgamma x) (list ival-tgamma x)]
7070
[(list 'trunc x) (list ival-trunc x)]
7171

main.rkt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@
140140
racket/cmdline)
141141
(define repl-mode repl-main)
142142
(command-line #:program "racket -l rival"
143-
#:once-each [("--profile") "Print timing results"
144-
(set! repl-mode repl-profile)]
143+
#:once-each [("--profile") "Print timing results" (set! repl-mode repl-profile)]
145144
#:args ([file #f])
146145
(if file
147146
(call-with-input-file file repl-mode)

ops/all.rkt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,33 @@
2222
ival-sub
2323
ival-sub!
2424
ival-neg
25+
ival-neg!
2526
ival-mult
2627
ival-mult!
2728
ival-div
2829
ival-div!
2930
ival-fma
3031
ival-fabs
3132
ival-sqrt
33+
ival-sqrt!
3234
ival-cbrt
35+
ival-cbrt!
3336
ival-hypot
3437
ival-hypot!
3538
ival-exp
39+
ival-exp!
3640
ival-exp2
41+
ival-exp2!
3742
ival-expm1
43+
ival-expm1!
3844
ival-log
45+
ival-log!
3946
ival-log2
47+
ival-log2!
4048
ival-log10
49+
ival-log10!
4150
ival-log1p
51+
ival-log1p!
4252
ival-logb
4353
ival-pow
4454
ival-pow2
@@ -49,22 +59,34 @@
4959
ival-sinu
5060
ival-tanu
5161
ival-asin
62+
ival-asin!
5263
ival-acos
64+
ival-acos!
5365
ival-atan
66+
ival-atan!
5467
ival-atan2
5568
ival-sinh
69+
ival-sinh!
5670
ival-cosh
71+
ival-cosh!
5772
ival-tanh
73+
ival-tanh!
5874
ival-asinh
75+
ival-asinh!
5976
ival-acosh
77+
ival-acosh!
6078
ival-atanh
79+
ival-atanh!
6180
ival-erf
81+
ival-erf!
6282
ival-erfc
83+
ival-erfc!
6384
ival-lgamma
6485
ival-tgamma
6586
ival-fmod
6687
ival-remainder
6788
ival-rint
89+
ival-rint!
6890
ival-round
6991
ival-ceil
7092
ival-floor

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-pre-fabs x))
165-
(define y* (ival-pre-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-pre-fabs x))
163+
(match-define (ival (endpoint ylo ylo!) (endpoint yhi yhi!) _ _) (ival-pre-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))

0 commit comments

Comments
 (0)