float32
Float32: IEEE 754’s single precision, 24 bits of precision, from
about 1.4e-45 to 3.4e38 — each operation’s result rounded to one, as
C’s float and JavaScript’s Math.fround round. A float literal
checked at Float32 is the one nearest it ((0.1 : Float32)).
Import it by a name, import float32 as Float32, as some of its names are
the prelude’s of a Float64 (sqrt, floor, toFloat): Float32.sqrt,
Float32.floor. Its instances are the prelude’s operators and functions
at Float32, wherever it is imported, by a name or not: x + 1.5,
-x, x /. y, x < y, max x y — but no /, as a float has none.
(Float64 is the double: toFloat and fromFloat go between them.)
float32Add
float32Add : Float32 -> Float32 -> Float32float32Sub
float32Sub : Float32 -> Float32 -> Float32float32Mul
float32Mul : Float32 -> Float32 -> Float32float32Div
float32Div : Float32 -> Float32 -> Float32float32Lt
float32Lt : Float32 -> Float32 -> Boolfloat32Le
float32Le : Float32 -> Float32 -> Boolfloat32Sqrt
float32Sqrt : Float32 -> Float32float32Show
float32Show : Float32 -> Stringfloat32FromFloat
float32FromFloat : Float64 -> Float32float32ToFloat
float32ToFloat : Float32 -> Float64float32FromInt
float32FromInt : Int -> Float32float32Floor
float32Floor : Float32 -> Intadd
add : Float32 -> Float32 -> Float32sub
sub : Float32 -> Float32 -> Float32mul
mul : Float32 -> Float32 -> Float32div
div : Float32 -> Float32 -> Float32Division; by 0, an infinity (or not a number, of 0 by 0).
sqrt
sqrt : Float32 -> Float32eq
eq : Float32 -> Float32 -> BoolEqual (what is not a number is equal to nothing, itself too).
lt
lt : Float32 -> Float32 -> Boolle
le : Float32 -> Float32 -> BoolisNaN
isNaN : Float32 -> BoolfromFloat
fromFloat : Float64 -> Float32The Float32 nearest the float.
toFloat
toFloat : Float32 -> Float64The same number, as a float (every Float32 is one).
fromInt
fromInt : Int -> Float32The Float32 nearest the float nearest the integer.
floor
floor : Float32 -> IntThe greatest integer not above; of an infinity, or what is not a number, 0.
>>> List.map floor [2.5, -2.5, div 1.0 0.0, div -1.0 0.0, div 0.0 0.0]Cons 2 (Cons (-3) (Cons 0 (Cons 0 (Cons 0 Nil))))instanceEqualityFloat32
instance instanceEqualityFloat32 : Equality Float32instanceDebugFloat32
instance instanceDebugFloat32 : Debug Float32The fewest digits that read back as the same Float32: debug 0.1
is "0.1", though the Float32 is 0.100000001490116…
>>> debug (7.5 : Float32)"7.5"instanceShowFloat32
instance instanceShowFloat32 : Show Float32As debug writes it.
instanceOrderFloat32
instance instanceOrderFloat32 : Order Float32instanceAdditionFloat32
instance instanceAdditionFloat32 : Addition Float32instanceSubtractionFloat32
instance instanceSubtractionFloat32 : Subtraction Float32instanceMultiplicationFloat32
instance instanceMultiplicationFloat32 : Multiplication Float32instanceNegationFloat32
instance instanceNegationFloat32 : Negation Float32The float of the other sign, 0.0’s too: what -x is.
>>> debug (-(2.5 * 3.0 - 0.0) + max 1.0 0.5 : Float32)"-6.5"instanceFloatDivisionFloat32
instance instanceFloatDivisionFloat32 : FloatDivision Float32Division, IEEE’s: what /. is (div, its own name).
>>> List.map debug ([1.0 /. 4.0, 1.0 /. -(0.0), 0.0 /. 0.0] : List Float32)Cons "0.25" (Cons "-Infinity" (Cons "NaN" Nil))fromDecimal
fromDecimal : Int -> Int -> Float32m times 10 to the power e, correctly rounded: the Float32
nearest it, a tie to the even, rounded once, not first to a
Float64 — beyond the greatest, an infinity, and below half the
least, 0.0 (with the sign of m) — as a float literal at Float32
is.
>>> fromDecimal 10000000596046448 (0 - 16)1.0000001>>> toFloat (fromDecimal 10000000596046448 (0 - 16))1.0000001192092896>>> fromDecimal 1 (0 - 45)1.0e-45>>> fromDecimal 34028236 31InfinityparseFloat32
parseFloat32 : String -> Maybe Float32The Float32 nearest the decimal s is, whole (2.5, -1e-7), as
the prelude’s floatOfDecimal reads one, if it is one: rounded once,
not first to a Float64, as fromDecimal rounds.
>>> parseFloat32 "1.0000000596046448"Just 1.0000001>>> parseFloat32 "1.00000005960464477539"Just 1.0>>> parseFloat32 "3.4028236e38"Just Infinity>>> parseFloat32 "x"Nothing