racket/fasl: fixed representation for +nan.0

To make fasl writing as determinsitic and portable as possible, write
+nan.0 and +nan.f always with a specific bit pattern.

This choice risks losing information that is potentially useful, but
given the way that Racket treats all NaN encodings as equivalent, that
rick seems low.
This commit is contained in:
Matthew Flatt 2019-03-12 16:06:55 -06:00
parent 6a35d64e95
commit e79f07b6cc

View File

@ -195,10 +195,18 @@
(write-fasl-integer v o)])]
[(flonum? v)
(write-byte fasl-flonum-type o)
(write-bytes (real->floating-point-bytes v 8 #f) o)]
(write-bytes (if (eqv? v +nan.0)
;; use a canonical NaN (0 mantissa)
#"\0\0\0\0\0\0\370\177"
(real->floating-point-bytes v 8 #f))
o)]
[(single-flonum? v)
(write-byte fasl-single-flonum-type o)
(write-bytes (real->floating-point-bytes v 4 #f) o)]
(write-bytes (if (eqv? v +nan.f)
;; use a canonical NaN (0 mantissa)
#"\0\0\300\177"
(real->floating-point-bytes v 4 #f))
o)]
[(extflonum? v)
(write-byte fasl-extflonum-type o)
(define bstr (string->bytes/utf-8 (format "~a" v)))