|
5 | 5 | bigfloats-between |
6 | 6 | bf-precision |
7 | 7 | bigfloat->string |
| 8 | + bigfloat? |
8 | 9 | bf)) |
9 | 10 | (require "eval/main.rkt" |
10 | 11 | "eval/machine.rkt" |
|
16 | 17 | (define body-type (rival-type body (map (curryr cons 'real) args))) |
17 | 18 | (match body-type |
18 | 19 | ['bool boolean-discretization] |
19 | | - ['real (bf-discretization (repl-precision repl))] |
| 20 | + ['real (repl-real-discretization repl)] |
20 | 21 | [#f (raise-user-error 'compile "Type error in function")]))) |
21 | 22 |
|
22 | 23 | (define (normalize-function-name name) |
23 | 24 | (if (string-prefix? name "ival-") |
24 | 25 | (substring name 5) |
25 | 26 | name)) |
26 | 27 |
|
| 28 | +(define (repl-real-discretization repl) |
| 29 | + (match (repl-precision repl) |
| 30 | + ['fp64 flonum-discretization] |
| 31 | + [`(bf ,n) (bf-discretization n)])) |
| 32 | + |
27 | 33 | (define (executions-iterations execs) |
28 | 34 | (define iter 0) |
29 | 35 | (define last #f) |
|
58 | 64 |
|
59 | 65 | (struct repl ([precision #:mutable] context)) |
60 | 66 |
|
61 | | -(define (make-repl [precision 53]) |
| 67 | +(define (make-repl [precision 'fp64]) |
62 | 68 | (repl precision (make-hash))) |
63 | 69 |
|
64 | 70 | (define (repl-compile repl args bodies) |
|
74 | 80 | (bf x) |
75 | 81 | x)) |
76 | 82 |
|
| 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 | + |
77 | 94 | (define (repl-apply repl machine vals) |
78 | 95 | (with-handlers ([exn:rival:invalid? (const "Domain error")] |
79 | 96 | [exn:rival:unsamplable? (const "Could not evaluate")]) |
80 | | - (parameterize ([bf-precision (repl-precision repl)]) |
| 97 | + (parameterize ([bf-precision (repl-precision-bits repl)]) |
81 | 98 | (rival-apply machine (list->vector (map ->bf vals)))))) |
82 | 99 |
|
83 | 100 | (define (repl-save-machine! repl name args bodies) |
|
174 | 191 | (for ([cmd (in-port read p)]) |
175 | 192 | (with-handlers ([exn:fail:user? (lambda (e) (eprintf "ERROR ~a\n" (exn-message e)))]) |
176 | 193 | (match cmd |
| 194 | + [`(set precision fp64) |
| 195 | + (set-repl-precision! repl 'fp64)] |
177 | 196 | [`(set precision ,(? integer? n)) |
178 | 197 | (when (< n 4) |
179 | 198 | (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))] |
181 | 200 | [`(define (,(? symbol? name) ,(? symbol? args) ...) |
182 | 201 | ,bodies ...) |
183 | 202 | (repl-save-machine! repl name args bodies)] |
|
0 commit comments