Browse Source

Coerce integers to floats/doubles during unparse

main
Tony Garnock-Jones 3 months ago
parent
commit
0d4d1e738c
  1. 2
      implementations/racket/preserves/preserves-schema/unparser.rkt
  2. 8
      implementations/racket/preserves/preserves/float.rkt

2
implementations/racket/preserves/preserves-schema/unparser.rkt

@ -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]

8
implementations/racket/preserves/preserves/float.rkt

@ -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))))
Loading…
Cancel
Save