-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
string_of_float returns -NaN
for most numbers formatted by printf
#16
Comments
That's possible; the (Aside: I wanted to use the musl implementation of |
FWIW the dtoa.c in mirage-xen and here are identical.. (modulo |
To clarify: I never got this far on xen since it lacked strtod last time I tried, so this bug could definitely be there too. I whipped up a quick C version with just one problematic number. Results were... baffling:
Compiling the above with
But without -O2:
And if I change the
... then with or without -O2, I get:
This seems consistent on my machine, but I'd be interested if others get the same results. |
Interesting. I get exactly the same results as you on Debian 9 (gcc 6.3.0) but on Debian 8 (gcc 4.9.2) I get |
Fixed in #28. |
mirage-solo5.pc should require ocaml-freestanding
I found this issue where yojson objects with timestamps (floats) were being serialized OK, but when deserialized they would came back as
-NaN
.To test, I ran the following code:
I got the following output in
mirage-ukvm
, with ocaml-freestanding 0.2.1:i.e. when using
string_of_float
the number correctly roundtrips to a string and back, but usingprintf
's float formatting it consistently gets parsed as-NaN
.2.4
was a random simple case I tried, and funnily enough it works both ways - perhaps the bug only affects numbers with a large number of decimal places?I remember
float_of_string
used to not work at all in xen becausestrtod
was missing(mirage/mirage-platform#118), so I'm guessing this is probably a bug in ocaml-freestanding's strtod?The text was updated successfully, but these errors were encountered: