You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if the language had an isSubnormal function to test if the number is subnormal.
One of the reasons I want this is that I would like to be able to print out the value of a floating point number without doing a foreign function interface call into the C library's printf. A CakeML implementation of a function to print out a floating point number would case split on the different classes of floating point ... which means it would be nice if there was an easy way to tell if its subnormal.
So, ok, I can Double.toWord the floating point number, pull out the exponent field, and test if it's zero. But it would be nicer if I had access to the underlying architecture's instruction for doing this test.
fun nonNegativeFloatToString(x) =
if isZero(x) then "0"
else if isInfinite(x) then "infinity"
else if isNaN(x) then "nan"
(* ought to handle subnormal numbers here *)
else "0x1." ^ digits(mantissa(x)) ^ "p" ^ Int.toString(exponent(x));
fun floatToString(x) =
if isSignMinus(x) then "~" ^ nonNegativeFloatToString(Double.~ x)
else nonNegativeFloatToString(x);
The text was updated successfully, but these errors were encountered:
Testing for the other classes of floating point is easy:
fun isZero (x) = Double.= x zero;
fun isInfinite(x) = Double.= x negInf orelse Double.= x posInf;
fun isNaN(x) = not (Double.= x x);
fun isSignMinus(x) = Word64.toIntSigned(Double.toWord(x)) < 0;
(Feature request)
It would be nice if the language had an isSubnormal function to test if the number is subnormal.
One of the reasons I want this is that I would like to be able to print out the value of a floating point number without doing a foreign function interface call into the C library's printf. A CakeML implementation of a function to print out a floating point number would case split on the different classes of floating point ... which means it would be nice if there was an easy way to tell if its subnormal.
So, ok, I can Double.toWord the floating point number, pull out the exponent field, and test if it's zero. But it would be nicer if I had access to the underlying architecture's instruction for doing this test.
The text was updated successfully, but these errors were encountered: