Floating-point operations. auto-imported.
Convert a float to its string representation.
float.to_string(3.14) // => \"3.14\
Truncate a float to an integer (rounds toward zero).
float.to_int(3.9) // => 3
Round a float to the nearest integer value (as Float).
float.round(3.6) // => 4.0
Round a float down to the nearest integer value (as Float).
float.floor(3.9) // => 3.0
Round a float up to the nearest integer value (as Float).
float.ceil(3.1) // => 4.0
Return the absolute value of a float.
float.abs(-2.5) // => 2.5
Return the square root of a float.
float.sqrt(9.0) // => 3.0
Parse a string into a float. Returns err if the string is not a valid number.
float.parse(\"3.14\") // => ok(3.14)
Convert an integer to a float.
float.from_int(42) // => 42.0
Return the smaller of two floats.
float.min(1.5, 2.5) // => 1.5
Return the larger of two floats.
float.max(1.5, 2.5) // => 2.5
Format a float with a fixed number of decimal places.
float.to_fixed(3.14159, 2) // => \"3.14\
Clamp a float to the range [lo, hi].
float.clamp(15.0, 0.0, 10.0) // => 10.0
Return the sign of a float: -1.0, 0.0, or 1.0.
float.sign(-3.5) // => -1.0
Check if a float is NaN (not a number).
float.is_nan(0.0 / 0.0) // => true
Check if a float is positive or negative infinity.
float.is_infinite(1.0 / 0.0) // => true
Reinterpret a float as its IEEE 754 bit representation (i64).
float.to_bits(1.0) // => 4607182418800017408