Skip to content

Commit

Permalink
Merge pull request #628 from herbie-fp/discontinuity-fix
Browse files Browse the repository at this point in the history
Fix errors from function discontinuities by converting infinities to valid JSON values.
  • Loading branch information
pavpanchekha authored Jun 30, 2023
2 parents 4d83bcd + 07a2134 commit 578f711
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/float.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ulp-difference ulps->bits
midpoint random-generate
</total <=/total
value->string value->json
value->string value->json json->value
real->repr repr->real)

(define (ulp-difference x y repr)
Expand Down Expand Up @@ -62,6 +62,20 @@
[_ (hash 'type (~a (representation-name repr))
'ordinal (~a ((representation-repr->ordinal repr) x)))]))

(define (json->value x repr)
(match x
[(? real?) x]
[(? hash?)
(match (hash-ref x 'type)
["real"
(match (hash-ref x 'value)
["-inf" -inf.0]
["+inf" +inf.0]
["NaN" +nan.0]
[_ +nan.0])]
[_ ((representation-ordinal->repr repr)
(string->number (hash-ref x 'ordinal)))])]))

(define (value->string n repr)
;; Prints a number with relatively few digits
(define ->bf (representation-repr->bf repr))
Expand Down
6 changes: 3 additions & 3 deletions src/points.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
(define-values (pts exs)
(for/lists (pts exs) ([entry (in-list json)])
(match-define (list pt ex) entry)
(values (map real->repr pt var-reprs) (real->repr ex output-repr))))
(values (map real->repr pt var-reprs) (real->repr (json->value ex output-repr) output-repr))))
(mk-pcontext pts exs))

(define (pcontext->json pcontext)
(define (pcontext->json pcontext repr)
(for/list ([(pt ex) (in-pcontext pcontext)])
(list pt ex)))
(list (map (curryr value->json repr) pt) (value->json ex repr))))
2 changes: 1 addition & 1 deletion src/web/demo.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
(define pctx (job-result-backend result))

(eprintf " complete\n")
(hasheq 'points (pcontext->json pctx)))))
(hasheq 'points (pcontext->json pctx (context-repr (test-context test)))))))

(define analyze-endpoint
(post-with-json-response
Expand Down

0 comments on commit 578f711

Please sign in to comment.