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 asinh(x: Float) -> Float

Returns the inverse hyperbolic sine of a number.

pub fn atan(x: Float) -> Float

Returns the arctangent of a number, in radians.

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 fn cbrt(x: Float) -> Float

Returns the cube root of a number.

pub fn cos(x: Float) -> Float

Returns the cosine of an angle in radians.

pub fn cosh(x: Float) -> Float

Returns the hyperbolic cosine of a number.

pub const e: Float

Euler’s number, the base of the natural logarithm.

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 const ln10: Float

The natural logarithm of 10.

pub const ln2: Float

The natural logarithm of 2.

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 const log10e: Float

The base-10 logarithm of e.

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 const log2e: Float

The base-2 logarithm of e.

pub const max_value: Float

The largest positive representable floating-point value.

pub const min_value: Float

The smallest positive representable floating-point value.

pub const pi: Float

The ratio of a circle’s circumference to its diameter.

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 sin(x: Float) -> Float

Returns the sine of an angle in radians.

pub fn sinh(x: Float) -> Float

Returns the hyperbolic sine of a number.

pub const sqrt1_2: Float

The square root of 1/2.

pub const sqrt2: Float

The square root of 2.

pub fn tan(x: Float) -> Float

Returns the tangent of an angle in radians.

pub fn tanh(x: Float) -> Float

Returns the hyperbolic tangent of a number.

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 0100. 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 0100. 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 1100. Equivalent to JavaScript’s Number.prototype.toPrecision.

Search Document