ieee_float
Types
Functions
pub fn absolute_value(f: IEEEFloat) -> IEEEFloat
Returns the absolute value of an IEEEFloat
.
pub fn ceiling(f: IEEEFloat) -> IEEEFloat
Rounds an IEEEFloat
to the next highest whole number.
pub fn clamp(
f: IEEEFloat,
min min_bound: IEEEFloat,
max max_bound: IEEEFloat,
) -> IEEEFloat
Restricts an IEEEFloat
between a lower and upper bound.
pub fn compare(
a: IEEEFloat,
with b: IEEEFloat,
) -> Result(Order, Nil)
Compares two IEEEFloats
, returning an Order
: Lt
for lower than, Eq
for equals, or Gt
for greater than. If either value is NaN then
Error(Nil)
is returned.
pub fn floor(f: IEEEFloat) -> IEEEFloat
Rounds an IEEEFloat
to the next lowest whole number.
pub fn from_bytes_16_be(bytes: BitArray) -> IEEEFloat
Converts bytes for a big endian 16-bit IEEE 754 float to an IEEEFloat
.
If the bit array doesn’t contain exactly two bytes then NaN is returned.
pub fn from_bytes_16_le(bytes: BitArray) -> IEEEFloat
Converts bytes for a little endian 16-bit IEEE 754 float to an IEEEFloat
.
If the bit array doesn’t contain exactly two bytes then NaN is returned.
pub fn from_bytes_32_be(bytes: BitArray) -> IEEEFloat
Converts bytes for a big endian 32-bit IEEE 754 float to an IEEEFloat
.
If the bit array doesn’t contain exactly four bytes then NaN is returned.
pub fn from_bytes_32_le(bytes: BitArray) -> IEEEFloat
Converts bytes for a little endian 32-bit IEEE 754 float to an IEEEFloat
.
If the bit array doesn’t contain exactly four bytes then NaN is returned.
pub fn from_bytes_64_be(bytes: BitArray) -> IEEEFloat
Converts bytes for a big endian 64-bit IEEE 754 float to an IEEEFloat
.
If the bit array doesn’t contain exactly eight bytes then NaN is returned.
pub fn from_bytes_64_le(bytes: BitArray) -> IEEEFloat
Converts bytes for a little endian 64-bit IEEE 754 float to an IEEEFloat
.
If the bit array doesn’t contain exactly eight bytes then NaN is returned.
pub fn is_finite(f: IEEEFloat) -> Bool
Returns whether an IEEEFloat
is finite. If it isn’t finite it is either
infinite or NaN.
pub fn is_nan(f: IEEEFloat) -> Bool
Returns whether an IEEEFloat
is NaN. If it isn’t NaN it is either finite
or infinite.
pub fn max(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat
Compares two IEEEFloat
s, returning the larger of the two.
pub fn min(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat
Compares two IEEEFloat
s, returning the smaller of the two.
pub fn multiply(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat
Multiplies two IEEEFloat
s together.
pub fn parse(s: String) -> IEEEFloat
Parses a string to an IEEEFloat
. If the string is not a valid float then
NaN is returned.
pub fn power(f: IEEEFloat, exp: IEEEFloat) -> IEEEFloat
Returns the results of the base being raised to the power of the exponent.
pub fn random() -> IEEEFloat
Generates a random IEEEFloat
between zero (inclusive) and one (exclusive).
On the Erlang target this updates the random state in the process dictionary. See https://www.erlang.org/doc/man/rand.html#uniform-0.
pub fn round(f: IEEEFloat) -> Result(Int, Nil)
Rounds an IEEEFloat
to the nearest whole number as an Int
. If the input
value is not finite then Error(Nil)
is returned.
pub fn square_root(f: IEEEFloat) -> IEEEFloat
Returns the square root of an IEEEFloat
.
pub fn subtract(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat
Subtracts one IEEEFloat
from another.
pub fn to_bytes_16_be(f: IEEEFloat) -> BitArray
Converts an IEEEFloat
to bytes for a big endian 16-bit IEEE 754 float.
pub fn to_bytes_16_le(f: IEEEFloat) -> BitArray
Converts an IEEEFloat
to bytes for a little endian 16-bit IEEE 754 float.
pub fn to_bytes_32_be(f: IEEEFloat) -> BitArray
Converts an IEEEFloat
to bytes for a big endian 32-bit IEEE 754 float.
pub fn to_bytes_32_le(f: IEEEFloat) -> BitArray
Converts an IEEEFloat
to bytes for a little endian 32-bit IEEE 754 float.
pub fn to_bytes_64_be(f: IEEEFloat) -> BitArray
Converts an IEEEFloat
to bytes for a big endian 64-bit IEEE 754 float.
pub fn to_bytes_64_le(f: IEEEFloat) -> BitArray
Converts an IEEEFloat
to bytes for a little endian 64-bit IEEE 754 float.
pub fn to_finite(f: IEEEFloat) -> Result(Float, Nil)
Converts an IEEEFloat
to the native Float
type. If the IEEEFloat
is
infinite or NaN then Error(Nil)
is returned.