Skip to content

Commit 07a2134

Browse files
committed
Write json->value function and use it to convert values in json->pcontext.
1 parent 9862b07 commit 07a2134

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/float.rkt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ulp-difference ulps->bits
99
midpoint random-generate
1010
</total <=/total
11-
value->string value->json
11+
value->string value->json json->value
1212
real->repr repr->real)
1313

1414
(define (ulp-difference x y repr)
@@ -62,6 +62,20 @@
6262
[_ (hash 'type (~a (representation-name repr))
6363
'ordinal (~a ((representation-repr->ordinal repr) x)))]))
6464

65+
(define (json->value x repr)
66+
(match x
67+
[(? real?) x]
68+
[(? hash?)
69+
(match (hash-ref x 'type)
70+
["real"
71+
(match (hash-ref x 'value)
72+
["-inf" -inf.0]
73+
["+inf" +inf.0]
74+
["NaN" +nan.0]
75+
[_ +nan.0])]
76+
[_ ((representation-ordinal->repr repr)
77+
(string->number (hash-ref x 'ordinal)))])]))
78+
6579
(define (value->string n repr)
6680
;; Prints a number with relatively few digits
6781
(define ->bf (representation-repr->bf repr))

src/points.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
(define-values (pts exs)
9292
(for/lists (pts exs) ([entry (in-list json)])
9393
(match-define (list pt ex) entry)
94-
(values (map real->repr pt var-reprs) (real->repr ex output-repr))))
94+
(values (map real->repr pt var-reprs) (real->repr (json->value ex output-repr) output-repr))))
9595
(mk-pcontext pts exs))
9696

9797
(define (pcontext->json pcontext repr)

0 commit comments

Comments
 (0)