Skip to content

Commit

Permalink
Documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-viney committed Jun 13, 2024
1 parent 57f2dec commit 98f7c94
Showing 1 changed file with 29 additions and 37 deletions.
66 changes: 29 additions & 37 deletions src/ieee_float.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Sign {
Negative
}

/// Returns a finite floating point value.
/// Creates a new `IEEEFloat` from a `Float`.
///
@external(javascript, "./ieee_float_js.mjs", "finite")
pub fn finite(f: Float) -> IEEEFloat {
Expand All @@ -44,15 +44,15 @@ pub fn negative_infinity() -> IEEEFloat {
Infinite(Negative)
}

/// Returns the NaN value.
/// Returns the `NaN` value.
///
@external(javascript, "./ieee_float_js.mjs", "nan")
pub fn nan() -> IEEEFloat {
NaN
}

/// Returns whether an `IEEEFloat` is finite. If it isn't finite it is either
/// infinite or NaN.
/// infinite or `NaN`.
///
@external(javascript, "./ieee_float_js.mjs", "is_finite")
pub fn is_finite(f: IEEEFloat) -> Bool {
Expand Down Expand Up @@ -109,8 +109,7 @@ pub fn parse(s: String) -> IEEEFloat {
}
}

/// Converts an `IEEEFloat` to bytes for a little endian 32-bit IEEE 754 float
/// point value.
/// Converts an `IEEEFloat` to bytes for a little endian 32-bit IEEE 754 float.
///
@external(javascript, "./ieee_float_js.mjs", "to_bytes_32_le")
pub fn to_bytes_32_le(f: IEEEFloat) -> BitArray {
Expand All @@ -122,8 +121,7 @@ pub fn to_bytes_32_le(f: IEEEFloat) -> BitArray {
}
}

/// Converts bytes for a little endian 32-bit IEEE 754 float point value to an
/// `IEEEFloat`.
/// Converts bytes for a little endian 32-bit IEEE 754 float to an `IEEEFloat`.
///
@external(javascript, "./ieee_float_js.mjs", "from_bytes_32_le")
pub fn from_bytes_32_le(bytes: BitArray) -> IEEEFloat {
Expand All @@ -135,8 +133,7 @@ pub fn from_bytes_32_le(bytes: BitArray) -> IEEEFloat {
}
}

/// Converts an `IEEEFloat` to bytes for a big endian 32-bit IEEE 754 float
/// point value.
/// Converts an `IEEEFloat` to bytes for a big endian 32-bit IEEE 754 float.
///
@external(javascript, "./ieee_float_js.mjs", "to_bytes_32_be")
pub fn to_bytes_32_be(f: IEEEFloat) -> BitArray {
Expand All @@ -148,8 +145,7 @@ pub fn to_bytes_32_be(f: IEEEFloat) -> BitArray {
}
}

/// Converts bytes for a big endian 32-bit IEEE 754 float point value to an
/// `IEEEFloat`.
/// Converts bytes for a big endian 32-bit IEEE 754 float to an `IEEEFloat`.
///
@external(javascript, "./ieee_float_js.mjs", "from_bytes_32_be")
pub fn from_bytes_32_be(bytes: BitArray) -> IEEEFloat {
Expand All @@ -161,8 +157,7 @@ pub fn from_bytes_32_be(bytes: BitArray) -> IEEEFloat {
}
}

/// Converts an `IEEEFloat` to bytes for a little endian 64-bit IEEE 754 float
/// point value.
/// Converts an `IEEEFloat` to bytes for a little endian 64-bit IEEE 754 float.
///
@external(javascript, "./ieee_float_js.mjs", "to_bytes_64_le")
pub fn to_bytes_64_le(f: IEEEFloat) -> BitArray {
Expand All @@ -174,8 +169,7 @@ pub fn to_bytes_64_le(f: IEEEFloat) -> BitArray {
}
}

/// Converts bytes for a little endian 64-bit IEEE 754 float point value to an
/// `IEEEFloat`.
/// Converts bytes for a little endian 64-bit IEEE 754 float to an `IEEEFloat`.
///
@external(javascript, "./ieee_float_js.mjs", "from_bytes_64_le")
pub fn from_bytes_64_le(bytes: BitArray) -> IEEEFloat {
Expand All @@ -187,8 +181,7 @@ pub fn from_bytes_64_le(bytes: BitArray) -> IEEEFloat {
}
}

/// Converts an `IEEEFloat` to bytes for a big endian 64-bit IEEE 754 float
/// point value.
/// Converts an `IEEEFloat` to bytes for a big endian 64-bit IEEE 754 float.
///
@external(javascript, "./ieee_float_js.mjs", "to_bytes_64_be")
pub fn to_bytes_64_be(f: IEEEFloat) -> BitArray {
Expand All @@ -200,8 +193,7 @@ pub fn to_bytes_64_be(f: IEEEFloat) -> BitArray {
}
}

/// Converts bytes for a big endian 64-bit IEEE 754 float point value to an
/// `IEEEFloat`.
/// Converts bytes for a big endian 64-bit IEEE 754 float to an `IEEEFloat`.
///
@external(javascript, "./ieee_float_js.mjs", "from_bytes_64_be")
pub fn from_bytes_64_be(bytes: BitArray) -> IEEEFloat {
Expand Down Expand Up @@ -245,9 +237,9 @@ fn rescue_bad_arith(do: fn() -> a) -> Result(a, Nil) {
/// Returns the absolute value of an `IEEEFloat`.
///
@external(javascript, "./ieee_float_js.mjs", "absolute_value")
pub fn absolute_value(a: IEEEFloat) -> IEEEFloat {
case a {
Finite(a) -> a |> float.absolute_value |> Finite
pub fn absolute_value(f: IEEEFloat) -> IEEEFloat {
case f {
Finite(f) -> f |> float.absolute_value |> Finite
Infinite(_) -> Infinite(Positive)
NaN -> NaN
}
Expand Down Expand Up @@ -285,10 +277,10 @@ pub fn add(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat {
/// Rounds an `IEEEFloat` to the next highest whole number.
///
@external(javascript, "./ieee_float_js.mjs", "ceiling")
pub fn ceiling(a: IEEEFloat) -> IEEEFloat {
case a {
Finite(a) -> a |> float.ceiling |> Finite
f -> f
pub fn ceiling(f: IEEEFloat) -> IEEEFloat {
case f {
Finite(f) -> f |> float.ceiling |> Finite
_ -> f
}
}

Expand Down Expand Up @@ -381,10 +373,10 @@ pub fn divide(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat {
/// Rounds an `IEEEFloat` to the next lowest whole number.
///
@external(javascript, "./ieee_float_js.mjs", "floor")
pub fn floor(a: IEEEFloat) -> IEEEFloat {
case a {
Finite(a) -> a |> float.floor |> Finite
a -> a
pub fn floor(f: IEEEFloat) -> IEEEFloat {
case f {
Finite(f) -> f |> float.floor |> Finite
_ -> f
}
}

Expand Down Expand Up @@ -452,9 +444,9 @@ pub fn multiply(a: IEEEFloat, b: IEEEFloat) -> IEEEFloat {
/// Returns the negative of an `IEEEFloat`.
///
@external(javascript, "./ieee_float_js.mjs", "negate")
pub fn negate(a: IEEEFloat) -> IEEEFloat {
case a {
Finite(a) -> a |> float.negate |> Finite
pub fn negate(f: IEEEFloat) -> IEEEFloat {
case f {
Finite(f) -> f |> float.negate |> Finite
Infinite(Positive) -> Infinite(Negative)
Infinite(Negative) -> Infinite(Positive)
NaN -> NaN
Expand All @@ -464,7 +456,7 @@ pub fn negate(a: IEEEFloat) -> 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.
/// dictionary. See <https://www.erlang.org/doc/man/rand.html#uniform-0>.
///
@external(javascript, "./ieee_float_js.mjs", "random")
pub fn random() -> IEEEFloat {
Expand All @@ -475,9 +467,9 @@ pub fn random() -> IEEEFloat {
/// value is not finite then `Error(Nil)` is returned.
///
@external(javascript, "./ieee_float_js.mjs", "round")
pub fn round(a: IEEEFloat) -> Result(Int, Nil) {
case a {
Finite(a) -> a |> float.round |> Ok
pub fn round(f: IEEEFloat) -> Result(Int, Nil) {
case f {
Finite(f) -> f |> float.round |> Ok
_ -> Error(Nil)
}
}
Expand Down

0 comments on commit 98f7c94

Please sign in to comment.