ieee_float

Types

An IEEE 754 compliant floating point value that can be either a finite number, positive infinity, negative infinity, or NaN (not a number).

On the JavaScript target, an IEEEFloat is a number.

pub opaque type IEEEFloat

Functions

pub fn absolute_value(f: IEEEFloat) -> IEEEFloat

Returns the absolute value of an IEEEFloat.

pub fn add(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat

Adds two IEEEFloats together.

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 divide(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat

Divides one IEEEFloat by another.

pub fn finite(f: Float) -> IEEEFloat

Creates a new IEEEFloat from a Float.

pub fn floor(f: IEEEFloat) -> IEEEFloat

Rounds an IEEEFloat to the next lowest whole number.

pub fn from_bytes_32_be(bytes: BitArray) -> IEEEFloat

Converts bytes for a big endian 32-bit IEEE 754 float to an IEEEFloat.

pub fn from_bytes_32_le(bytes: BitArray) -> IEEEFloat

Converts bytes for a little endian 32-bit IEEE 754 float to an IEEEFloat.

pub fn from_bytes_64_be(bytes: BitArray) -> IEEEFloat

Converts bytes for a big endian 64-bit IEEE 754 float to an IEEEFloat.

pub fn from_bytes_64_le(bytes: BitArray) -> IEEEFloat

Converts bytes for a little endian 64-bit IEEE 754 float to an IEEEFloat.

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 IEEEFloats, returning the larger of the two.

pub fn min(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat

Compares two IEEEFloats, returning the smaller of the two.

pub fn multiply(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat

Multiplies two IEEEFloats together.

pub fn nan() -> IEEEFloat

Returns the NaN value.

pub fn negate(f: IEEEFloat) -> IEEEFloat

Returns the negative of an IEEEFloat.

pub fn negative_infinity() -> IEEEFloat

Returns the negative infinity value.

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 positive_infinity() -> IEEEFloat

Returns the positive infinity value.

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_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.

pub fn to_string(f: IEEEFloat) -> String

Formats an IEEEFloat as a string.

Search Document