gossamer/float_extra
Extras for gleam/float — JavaScript Number representation
constants, mathematical constants and operations, and number
formatting that gleam/float doesn’t cover.
For locale-aware number formatting, use
gossamer/intl/number_format.
Values
pub fn acos(x: Float) -> Result(Float, Nil)
Returns the arccosine of a number, in radians. Returns an error if
the value is outside the range -1.0 to 1.0.
pub fn acosh(x: Float) -> Result(Float, Nil)
Returns the inverse hyperbolic cosine of a number. Returns an error
if the value is less than 1.0.
pub fn asin(x: Float) -> Result(Float, Nil)
Returns the arcsine of a number, in radians. Returns an error if
the value is outside the range -1.0 to 1.0.
pub fn atan2(y: Float, x: Float) -> Float
Returns the angle in radians between the positive x-axis and the
point (x, y), with the result in the range -pi to pi.
pub fn atanh(x: Float) -> Result(Float, Nil)
Returns the inverse hyperbolic tangent of a number. Returns an
error if the absolute value is greater than or equal to 1.0.
pub const epsilon: Float
The difference between 1.0 and the smallest representable
floating-point value greater than 1.0.
pub fn expm1(x: Float) -> Float
Returns e raised to the power of a number minus 1, precise for
small values.
pub fn f16round(x: Float) -> Float
Returns the nearest 16-bit half-precision float representation of a number.
pub fn fround(x: Float) -> Float
Returns the nearest 32-bit single-precision float representation of a number.
pub fn hypot(numbers: List(Float)) -> Float
Returns the square root of the sum of the squares of its values.
The two-dimensional case is the hypotenuse sqrt(x*x + y*y); the
general case is the Euclidean norm of a vector. An empty list
returns 0.0.
Examples
float_extra.hypot([3.0, 4.0])
// -> 5.0
float_extra.hypot([1.0, 2.0, 2.0])
// -> 3.0
pub fn log10(x: Float) -> Result(Float, Nil)
Returns the base-10 logarithm of a number. Returns an error if the value is not positive.
pub fn log1p(x: Float) -> Result(Float, Nil)
Returns the natural logarithm of 1 + x, precise for small
values. Returns an error if x is less than or equal to -1.0.
pub fn log2(x: Float) -> Result(Float, Nil)
Returns the base-2 logarithm of a number. Returns an error if the value is not positive.
pub fn sign(x: Float) -> Float
Returns 1.0 for a positive number, -1.0 for a negative number,
and 0.0 for zero. Equivalent to JavaScript’s Math.sign.
pub fn to_exponential_string(
x: Float,
digits: Int,
) -> Result(String, Nil)
Formats a number in exponential (scientific) notation with the
specified number of digits after the decimal point. Returns an
error if digits is outside 0–100. Equivalent to JavaScript’s
Number.prototype.toExponential.
pub fn to_fixed_string(
x: Float,
digits: Int,
) -> Result(String, Nil)
Formats a number using fixed-point notation with the specified
number of decimal places. Returns an error if digits is outside
0–100. Equivalent to JavaScript’s Number.prototype.toFixed.
pub fn to_precision_string(
x: Float,
digits: Int,
) -> Result(String, Nil)
Formats a number to the specified number of significant digits.
Returns an error if digits is outside 1–100. Equivalent to
JavaScript’s Number.prototype.toPrecision.