Skip to content

Commit 9a0d37b

Browse files
committed
Add (set precision fp64) for Herbie to possibly use
1 parent c89fbe7 commit 9a0d37b

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

repl.rkt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
bigfloats-between
66
bf-precision
77
bigfloat->string
8+
bigfloat?
89
bf))
910
(require "eval/main.rkt"
1011
"eval/machine.rkt"
@@ -16,14 +17,19 @@
1617
(define body-type (rival-type body (map (curryr cons 'real) args)))
1718
(match body-type
1819
['bool boolean-discretization]
19-
['real (bf-discretization (repl-precision repl))]
20+
['real (repl-real-discretization repl)]
2021
[#f (raise-user-error 'compile "Type error in function")])))
2122

2223
(define (normalize-function-name name)
2324
(if (string-prefix? name "ival-")
2425
(substring name 5)
2526
name))
2627

28+
(define (repl-real-discretization repl)
29+
(match (repl-precision repl)
30+
['fp64 flonum-discretization]
31+
[`(bf ,n) (bf-discretization n)]))
32+
2733
(define (executions-iterations execs)
2834
(define iter 0)
2935
(define last #f)
@@ -58,7 +64,7 @@
5864

5965
(struct repl ([precision #:mutable] context))
6066

61-
(define (make-repl [precision 53])
67+
(define (make-repl [precision 'fp64])
6268
(repl precision (make-hash)))
6369

6470
(define (repl-compile repl args bodies)
@@ -74,10 +80,21 @@
7480
(bf x)
7581
x))
7682

83+
(define (repl-value->string val)
84+
(cond
85+
[(bigfloat? val) (bigfloat->string val)]
86+
[(number? val) (~r val)]
87+
[else (~a val)]))
88+
89+
(define (repl-precision-bits repl)
90+
(match (repl-precision repl)
91+
[`(bf ,n) n]
92+
['fp64 53]))
93+
7794
(define (repl-apply repl machine vals)
7895
(with-handlers ([exn:rival:invalid? (const "Domain error")]
7996
[exn:rival:unsamplable? (const "Could not evaluate")])
80-
(parameterize ([bf-precision (repl-precision repl)])
97+
(parameterize ([bf-precision (repl-precision-bits repl)])
8198
(rival-apply machine (list->vector (map ->bf vals))))))
8299

83100
(define (repl-save-machine! repl name args bodies)
@@ -174,10 +191,12 @@
174191
(for ([cmd (in-port read p)])
175192
(with-handlers ([exn:fail:user? (lambda (e) (eprintf "ERROR ~a\n" (exn-message e)))])
176193
(match cmd
194+
[`(set precision fp64)
195+
(set-repl-precision! repl 'fp64)]
177196
[`(set precision ,(? integer? n))
178197
(when (< n 4)
179198
(raise-user-error 'set "Precision must be an integer greater than 3"))
180-
(set-repl-precision! repl n)]
199+
(set-repl-precision! repl (list 'bf n))]
181200
[`(define (,(? symbol? name) ,(? symbol? args) ...)
182201
,bodies ...)
183202
(repl-save-machine! repl name args bodies)]

0 commit comments

Comments
 (0)