Version
110.99.8 (Latest)
Operating System
OS Version
macOS Sequoia 15.5
Processor
System Component
Basis Library
Severity
Major
Description
Real.fromString returns incorrect values. I've found a few examples, see below.
My best guess at the moment: the bug seems to occur when there are 18 or more decimal digits past the decimal point. All of the examples below have 18 decimal digits. Increasing the number of decimal digits even further causes the outputs to change.
Transcript
A few examples of incorrect outputs from Real.fromString:
Standard ML of New Jersey [Version 110.99.8; 64-bit; April 25, 2025]
- Real.fromString "0.501782303180000055";
val it = SOME 502.812494993 : real option
- Real.fromString "0.211111111111111111";
val it = SOME 9.46111993270 : real option
- Real.fromString "0.311111111111111111";
val it = SOME 418.928139547 : real option
- Real.fromString "0.411111111111111111";
val it = SOME 316.528139547 : real option
Expected Behavior
Not sure about exact values (this will depend on printing conventions), but the above are clearly wrong.
FWIW, here is output from MLton:
$ cat foo.sml
fun dump x =
print (Real.fmt StringCvt.EXACT (valOf (Real.fromString x)) ^ "\n")
val () = dump "0.501782303180000055"
val () = dump "0.211111111111111111"
val () = dump "0.311111111111111111"
val () = dump "0.411111111111111111"
$ mlton foo.sml
$ ./foo
0.50178230318
0.2111111111111111
0.3111111111111111
0.4111111111111111
Steps to Reproduce
See above.
Additional Information
No response
Email address
github username at gmail
Version
110.99.8 (Latest)
Operating System
OS Version
macOS Sequoia 15.5
Processor
System Component
Basis Library
Severity
Major
Description
Real.fromStringreturns incorrect values. I've found a few examples, see below.My best guess at the moment: the bug seems to occur when there are 18 or more decimal digits past the decimal point. All of the examples below have 18 decimal digits. Increasing the number of decimal digits even further causes the outputs to change.
Transcript
A few examples of incorrect outputs from
Real.fromString:Expected Behavior
Not sure about exact values (this will depend on printing conventions), but the above are clearly wrong.
FWIW, here is output from MLton:
Steps to Reproduce
See above.
Additional Information
No response
Email address
github username at gmail