gleam/float
Types
Float
pub type Float = Float
Functions
absolute_value
pub external fn absolute_value(Float) -> Float
Returns the absolute value of the input as a float.
Examples
> absolute_value(-12.5)
12.5
> absolute_value(10.2)
10.2
ceiling
pub external fn ceiling(Float) -> Float
Rounds the value to the next highest whole number as a float.
Examples
> ceiling(2.3)
3.0
compare
pub fn compare(a: Float, with b: Float) -> Order
Compares two floats, returning an order.
Examples
> compare(2.0, 2.3)
Lt
floor
pub external fn floor(Float) -> Float
Rounds the value to the next lowest whole number as a float.
Examples
> floor(2.3)
2.0
max
pub fn max(a: Float, b: Float) -> Float
Compares two floats, returning the larger of the two.
Examples
> max(2.0, 2.3)
2.3
min
pub fn min(a: Float, b: Float) -> Float
Compares two floats, returning the smaller of the two.
Examples
> min(2.0, 2.3)
2.0
negate
pub fn negate(x: Float) -> Float
Returns the negative of the value provided
Examples
> negate(1.)
-1.
parse
pub external fn parse(String) -> Result(Float, Nil)
Attempts to parse a string as a float, returning Error(Nil)
if it was not
possible.
Examples
> parse("2.3")
Some(2.3)
> parse("ABC")
None
power
pub external fn power(base: Float, exponent: Float) -> Float
Returns the results of the base being raised to the power of the exponent, as a float.
Examples
> power(2.0, 2.0)
4.0
> power(8.0, 1.5)
64.0
round
pub external fn round(Float) -> Int
Rounds the value to the nearest whole number as an int.
Examples
> round(2.3)
2
> round(2.5)
3
square_root
pub fn square_root(number: Float) -> Result(Float, Nil)
Returns the square root of the input as a float.
Examples
> square_root(4.0)
Ok(2.0)
> square_root(-16.0)
Error(Nil)
to_string
pub fn to_string(f: Float) -> String
Return the string representation of the provided float.
Examples
> to_string(2.3)
"2.3"
truncate
pub external fn truncate(Float) -> Int
Returns the value as an int, truncating all decimal digits.
Examples
> truncate(2.4343434847383438)
2