gossamer/number
Numeric constants, type checks, parsing, and formatting that mirror
JavaScript’s Number object.
Values
pub fn epsilon() -> Float
The difference between 1 and the smallest floating-point number greater
than 1.
pub fn is_finite(value: Float) -> Bool
Returns whether the value is a finite number (not NaN or Infinity).
pub fn is_integer(value: Float) -> Bool
Returns whether the value is an integer (has no fractional part).
pub fn is_safe_integer(value: Float) -> Bool
Returns whether the value is a safe integer — an integer that can be exactly represented as an IEEE 754 double and has no other integer that rounds to the same representation.
pub const max_safe_integer: Int
The maximum safe integer in JavaScript (2^53 - 1).
pub const min_safe_integer: Int
The minimum safe integer in JavaScript (-(2^53 - 1)).
pub fn min_value() -> Float
The smallest positive representable floating-point number.
pub fn parse_float(string: String) -> Result(Float, Nil)
Parses a string as a floating-point number. Returns an error if the string cannot be parsed.
pub fn parse_int(
string: String,
radix radix: Int,
) -> Result(Int, Nil)
Parses a string as an integer in the specified radix (base 2–36). Returns
an error if the string cannot be parsed.
pub fn to_exponential(
value: Float,
digits digits: Int,
) -> Result(String, js_error.JsError)
Formats a number in exponential (scientific) notation with the specified
number of digits after the decimal point. Returns an error if the digits
are out of range (0–100).
pub fn to_fixed(
value: Float,
digits digits: Int,
) -> Result(String, js_error.JsError)
Formats a number using fixed-point notation with the specified number of
decimal places. Returns an error if the digits are out of range (0–100).
pub fn to_locale_string(value: Float) -> String
Returns a locale-sensitive string representation of the number.
pub fn to_precision(
value: Float,
digits digits: Int,
) -> Result(String, js_error.JsError)
Formats a number to the specified number of significant digits. Returns
an error if the precision is out of range (1–100).
pub fn to_string_with_radix(
value: Int,
radix radix: Int,
) -> Result(String, js_error.JsError)
Converts an integer to a string in the specified radix (base 2–36).
Returns an error if the radix is out of range.