Skip to content

Std.Dynamic.Number

opaque type Number

A decimal number of any size and precision: a sign, digits and an exponent. Two numbers that denote the same value are equal (1.0 and 1e0).

error OutOfRange(number: Number)

A number that the target type cannot hold.

  • number: Number
fn parse(s: String) -> Number fails ParseError

Reads a number in the JSON grammar: an optional -, an integer part without leading zeros, an optional . and fraction, and an optional e or E with an optional sign and digits. Fails also when the normalized exponent is outside the range of Int.

fn from_int(n: Int) -> Number

The number n, exactly.

fn from_int64(n: Int64) -> Number

The number n, exactly.

fn from_float(f: Float) -> Option[Number]

None for NaN and the infinities, which no number can hold.

fn to_int(n: Number) -> Int fails OutOfRange

n as an Int. Fails if n is not an integer or is outside the range of Int.

fn to_int64(n: Number) -> Int64 fails OutOfRange

n as an Int64. Fails if n is not an integer or is outside the range of Int64.

fn to_float(n: Number) -> Float

The Float nearest to n.

fn to_string(n: Number) -> String

Integral values up to 21 digits are written in full (1500), values with a short enough fraction with a point (0.25), and the rest with an exponent (1.5e300).