Coerce integers to floats/doubles during unparse

This commit is contained in:
Tony Garnock-Jones 2021-06-09 20:02:06 +02:00
parent feb6361029
commit 0d4d1e738c
2 changed files with 9 additions and 1 deletions

View File

@ -14,6 +14,8 @@
(match (unwrap pattern)
[(NamedSimplePattern_ n p) (pattern->unparser p (escape n))]
[(SimplePattern-any) src-stx]
[(SimplePattern-atom (AtomKind-Float)) `(->float ,src-stx)]
[(SimplePattern-atom (AtomKind-Double)) `(exact->inexact ,src-stx)]
[(SimplePattern-atom _) src-stx]
[(SimplePattern-embedded _interface) `(embedded ,src-stx)]
[(SimplePattern-lit v) `',v]

View File

@ -3,6 +3,12 @@
;; precision (de)serialization. In many circumstances, Racket lacks
;; 32-bit floating point support, and single-flonum? always yields #f.
(provide (struct-out float))
(provide (struct-out float)
->float)
(struct float (value) #:transparent)
(define (->float v)
(if (float? v)
v
(float (exact->inexact v))))