Menu

#7 Real.fmt StringCvt.EXACT formats NaN with leading "~"

open
nobody
None
5
2012-12-12
2011-12-15
No

Real.fmt StringCvt.EXACT should not format NaN with a leading "~" even when the sign bit is set, according to the Basis Library:
http://www.standardml.org/Basis/real.html#SIG:REAL.fmt:VAL
which states:
...and NaN values are converted to the string "nan".

Confusingly, the paragraph before defines the behaviour for EXACT by referring to IEEEReal.toString which does prefix NaN with a "~" when the sign bit is set. So that Basis Library appears contradictory in that detail. It is not clear why output from Real.fmt should not show the sign of NaN, given that functions can influence the sign of NaN.

Note that MLton does not prefix NaN with "~" for Real.fmt StringCvt.EXACT. Compare the output of the following code:

val plusNan = {class = IEEEReal.NAN, sign = false, digits = [], exp = 0};
val minusNan = {class = IEEEReal.NAN, sign = true, digits = [], exp = 0};
app print [
IEEEReal.toString plusNan, "\n",
IEEEReal.toString minusNan, "\n",
Real.fmt StringCvt.EXACT (valOf (Real.fromDecimal plusNan)), "\n",
Real.fmt StringCvt.EXACT (valOf (Real.fromDecimal minusNan)), "\n"
];

Discussion


Log in to post a comment.