Data.Float

lib/Data/Float.gob

No module comment.

type Float = Float

The 64-bit IEEE 754 float, which the compiler provides.

fun toString : fun(Float) -> String

The shortest decimal that parses back to the same Float; see Data.Float.Text for the layout.

fun parse : fun(String) -> Option Float

Accepts everything toString produces, Infinity and NaN included -- which matters because those two have no literal syntax, so parsing is the only way to write them down. Correctly rounded: the nearest Float, ties to even.

fun fromInt : fun(Int) -> Float

Total, but exact only to 2^53; past that it rounds to nearest, ties to even. Not a widening conversion, whatever the names suggest.

fun truncate : fun(Float) -> Option Int

None for NaN, either infinity, and anything whose truncation falls outside Int. The Option is not fussiness: out of range, fcvtzs saturates to the nearest Int and a NaN becomes 0, so an unchecked version would answer a number the value does not truncate to.

fun floor : fun(Float) -> Float
fun ceil : fun(Float) -> Float
fun round : fun(Float) -> Float
fun trunc : fun(Float) -> Float
fun sqrt : fun(Float) -> Float
fun abs : fun(Float) -> Float

Clears the sign bit, so abs(-0.0) is 0.0 and abs(NaN) is a NaN. Not written as if x < 0 -- that comparison is false for NaN and for -0.0.

fun isNaN : fun(Float) -> Bool
fun infinity : fun() -> Float
fun nan : fun() -> Float
fun isInfinite : fun(Float) -> Bool
fun isFinite : fun(Float) -> Bool
fun bits : fun(Float) -> Int

The raw bit pattern. This is the only way to observe a NaN payload or tell 0.0 from -0.0; nothing else in the language distinguishes them, and there is deliberately no Hash Float built on it.

fun fromBits : fun(Int) -> Float
fun totalCompare : fun(Float, Float) -> Ordering
fun fmod : fun(Float, Float) -> Float

C's fmod (the remainder of truncating division) and IEEE's remainder (of round-to-nearest division) disagree, and neither deserves the % operator, so there is no Rem Float and both are spelled out.

fun remainder : fun(Float, Float) -> Float
instance Eq Float

Eq Float and Ord Float are the IEEE comparison predicates, and they are the one pair of instances in the language that does not satisfy its class's laws: Eq is not reflexive (NaN != NaN) and Ord is not total (every comparison with NaN is false). Turkey has one Ord and no PartialOrd split, so there is nowhere in the type system to put the distinction; it is written down here instead.

Every one of the four Ord methods is overridden. Inheriting the defaults would derive gte(x, y) as !lt(x, y), which makes gte(NaN, 1.0) true while lte(NaN, 1.0) is false -- neither IEEE nor anything else.

instance Ord Float
instance Add Float
instance Sub Float
instance Mul Float
instance Div Float

IEEE division: zero divisors give infinities and NaN, never a panic.

instance Neg Float
instance Zero Float
instance One Float
instance Show Float