Skip to content

Latest commit

 

History

History
139 lines (87 loc) · 2.32 KB

File metadata and controls

139 lines (87 loc) · 2.32 KB

float

Floating-point operations. auto-imported.

float.to_string(n: Float) -> String

Convert a float to its string representation.

float.to_string(3.14) // => \"3.14\

float.to_int(n: Float) -> Int

Truncate a float to an integer (rounds toward zero).

float.to_int(3.9) // => 3

float.round(n: Float) -> Float

Round a float to the nearest integer value (as Float).

float.round(3.6) // => 4.0

float.floor(n: Float) -> Float

Round a float down to the nearest integer value (as Float).

float.floor(3.9) // => 3.0

float.ceil(n: Float) -> Float

Round a float up to the nearest integer value (as Float).

float.ceil(3.1) // => 4.0

float.abs(n: Float) -> Float

Return the absolute value of a float.

float.abs(-2.5) // => 2.5

float.sqrt(n: Float) -> Float

Return the square root of a float.

float.sqrt(9.0) // => 3.0

float.parse(s: String) -> Result[Float, String]

Parse a string into a float. Returns err if the string is not a valid number.

float.parse(\"3.14\") // => ok(3.14)

float.from_int(n: Int) -> Float

Convert an integer to a float.

float.from_int(42) // => 42.0

float.min(a: Float, b: Float) -> Float

Return the smaller of two floats.

float.min(1.5, 2.5) // => 1.5

float.max(a: Float, b: Float) -> Float

Return the larger of two floats.

float.max(1.5, 2.5) // => 2.5

float.to_fixed(n: Float, decimals: Int) -> String

Format a float with a fixed number of decimal places.

float.to_fixed(3.14159, 2) // => \"3.14\

float.clamp(n: Float, lo: Float, hi: Float) -> Float

Clamp a float to the range [lo, hi].

float.clamp(15.0, 0.0, 10.0) // => 10.0

float.sign(n: Float) -> Float

Return the sign of a float: -1.0, 0.0, or 1.0.

float.sign(-3.5) // => -1.0

float.is_nan(n: Float) -> Bool

Check if a float is NaN (not a number).

float.is_nan(0.0 / 0.0) // => true

float.is_infinite(n: Float) -> Bool

Check if a float is positive or negative infinity.

float.is_infinite(1.0 / 0.0) // => true

float.to_bits(f: Float) -> Int

Reinterpret a float as its IEEE 754 bit representation (i64).

float.to_bits(1.0) // => 4607182418800017408