CakeML / CakeML/cakeml

Test for Subnormal Floating Point Numbers

Open
#920 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Standard ML
Stars
1.2k
Forks
104
Avg merge
2d 21h
Merged PRs (30d)
16

Description

(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.

```
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);

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.