Manuscript Documentation
v2026.12.0

@std/math/big.ms#

Import each required symbol with import Name from "@std/math/big.ms".

BigFloat Type#

An arbitrary-precision binary floating-point number, mantissa * 2^exponent, whose mantissa holds at most precision bits. Every operation rounds once, to nearest with ties to even, at the larger operand precision, so results are exact up to that single rounding. Zero is unsigned and there are no infinities or NaN: out-of-domain operations return a Result. Example: big_float_of_int(2, 100).sqrt() returns the square root of two to 100 bits as a Result, and to_fixed(30) formats it.

Manuscript
opaque type BigFloat {
}

BigFloat.abs#

Returns the absolute value.

Manuscript
fn abs() BigFloat

BigFloat.add#

Returns the sum, rounded once at the larger operand precision.

Manuscript
fn add(other BigFloat) BigFloat

BigFloat.clone#

Returns an independent copy.

Manuscript
fn clone() BigFloat

BigFloat.compare#

Returns -1, 0 or 1 as this value is less than, equal to or greater than other, ignoring precision.

Manuscript
fn compare(other BigFloat) Int

BigFloat.divide#

Returns the quotient, rounded once at the larger operand precision; a zero divisor returns EINVAL.

Manuscript
fn divide(other BigFloat) Result[BigFloat, Error]

BigFloat.max#

Returns the greater value, or this value when they compare equal.

Manuscript
fn max(other BigFloat) BigFloat

BigFloat.min#

Returns the lesser value, or this value when they compare equal.

Manuscript
fn min(other BigFloat) BigFloat

BigFloat.multiply#

Returns the product, rounded once at the larger operand precision.

Manuscript
fn multiply(other BigFloat) BigFloat

BigFloat.negate#

Returns the same magnitude with the opposite sign and unchanged precision; zero stays zero.

Manuscript
fn negate() BigFloat

BigFloat.precision#

Returns the precision in bits.

Manuscript
fn precision() Int

BigFloat.sign#

Returns -1, 0 or 1 by sign.

Manuscript
fn sign() Int

BigFloat.sqrt#

Returns the square root rounded once; a negative operand returns EINVAL.

Manuscript
fn sqrt() Result[BigFloat, Error]

BigFloat.subtract#

Returns the difference, rounded once at the larger operand precision.

Manuscript
fn subtract(other BigFloat) BigFloat

BigFloat.to_fixed#

Formats in plain decimal notation with exactly digits fractional digits, rounding ties to even. A negative digit count returns EINVAL.

Manuscript
fn to_fixed(digits Int) Result[String, Error]

BigFloat.to_float#

Converts to the nearest Float, or null when the magnitude is beyond the Float range.

Manuscript
fn to_float() Float?

BigFloat.to_rat#

Returns the exact value as a fraction.

Manuscript
fn to_rat() BigRat

BigFloat.truncate#

Discards the fraction toward zero.

Manuscript
fn truncate() BigInt

BigFloat.with_precision#

Returns this value rounded to precision bits; a precision outside 1 through 1000000 is a fault.

Manuscript
fn with_precision(precision Int) BigFloat

BigRat Type#

An exact fraction of two arbitrary-precision integers, always in lowest terms with a positive denominator, so two equal values compare equal with ==. Arithmetic uses named methods and never rounds. Build values with rat, rat_of_int, rat_of_big_int, rat_of_float or parse_rat. Example: (parse_rat("1/3")?).add(parse_rat("1/6")?).to_string() is "1/2".

Manuscript
opaque type BigRat {
}

BigRat.abs#

Returns the absolute value.

Manuscript
fn abs() BigRat

BigRat.add#

Returns the exact sum.

Manuscript
fn add(other BigRat) BigRat

BigRat.ceil#

Returns the smallest integer not less than this value.

Manuscript
fn ceil() BigInt

BigRat.clone#

Returns an independent copy.

Manuscript
fn clone() BigRat

BigRat.compare#

Returns -1, 0 or 1 as this value is less than, equal to or greater than other.

Manuscript
fn compare(other BigRat) Int

BigRat.denominator#

Returns the positive denominator.

Manuscript
fn denominator() BigInt

BigRat.divide#

Returns the exact quotient; a zero divisor returns EINVAL.

Manuscript
fn divide(other BigRat) Result[BigRat, Error]

BigRat.floor#

Returns the largest integer not greater than this value.

Manuscript
fn floor() BigInt

BigRat.invert#

Returns 1 / self; zero returns EINVAL.

Manuscript
fn invert() Result[BigRat, Error]

BigRat.is_integer#

Reports whether the denominator is 1, so the value is a whole number.

Manuscript
fn is_integer() Bool

BigRat.max#

Returns the greater value, or this value when they compare equal.

Manuscript
fn max(other BigRat) BigRat

BigRat.min#

Returns the lesser value, or this value when they compare equal.

Manuscript
fn min(other BigRat) BigRat

BigRat.multiply#

Returns the exact product.

Manuscript
fn multiply(other BigRat) BigRat

BigRat.negate#

Returns the same magnitude with the opposite sign; zero stays zero.

Manuscript
fn negate() BigRat

BigRat.numerator#

Returns the numerator, which carries the sign.

Manuscript
fn numerator() BigInt

BigRat.pow#

Returns the exact power. A negative exponent returns the reciprocal power, so zero with a negative exponent returns EINVAL. A numerator or denominator above 16777216 bits returns EOVERFLOW.

Manuscript
fn pow(exponent Int) Result[BigRat, Error]

BigRat.round#

Rounds to the nearest integer; an exact tie rounds away from zero.

Manuscript
fn round() BigInt

BigRat.sign#

Returns -1, 0 or 1 by sign.

Manuscript
fn sign() Int

BigRat.subtract#

Returns the exact difference.

Manuscript
fn subtract(other BigRat) BigRat

BigRat.to_fixed#

Formats in plain decimal notation with exactly digits fractional digits, rounding ties to even. A negative digit count returns EINVAL; a result that rounds to zero has no minus sign.

Manuscript
fn to_fixed(digits Int) Result[String, Error]

BigRat.to_float#

Converts to the nearest Float, or null when the magnitude is beyond the Float range.

Manuscript
fn to_float() Float?

BigRat.to_string#

Formats as a/b, or just a for an integer; parse_rat reads the result back.

Manuscript
fn to_string() String

BigRat.truncate#

Discards the fraction toward zero.

Manuscript
fn truncate() BigInt

big_float_of_big_int Function#

Returns value rounded to precision bits; a precision outside 1 through 1000000 is a fault.

Manuscript
fn big_float_of_big_int(value BigInt, precision Int) BigFloat { ... }

big_float_of_float Function#

Returns a Float rounded to precision bits (exact when precision is at least 53), or null for NaN and infinities.

Manuscript
fn big_float_of_float(value Float, precision Int) BigFloat? { ... }

big_float_of_int Function#

Returns value rounded to precision bits; a precision outside 1 through 1000000 is a fault.

Manuscript
fn big_float_of_int(value Int, precision Int) BigFloat { ... }

big_float_of_rat Function#

Returns the rational rounded once to precision bits.

Manuscript
fn big_float_of_rat(value BigRat, precision Int) BigFloat { ... }

max_big_float_precision Constant#

The largest supported precision in bits.

Manuscript
max_big_float_precision Int

parse_big_float Function#

Parses an integer or decimal with optional exponent (2, -0.1, 6.02e23) and rounds once to precision bits. Malformed text returns EBADMSG and an exponent beyond 100000 in magnitude EOVERFLOW.

Manuscript
fn parse_big_float(text String, precision Int) Result[BigFloat, Error] { ... }

parse_rat Function#

Parses a/b, an integer, or a decimal with an optional exponent: 3/4, -12, 1.25, 6.02e23, 5e-3. A zero denominator returns EINVAL, malformed text EBADMSG and an exponent beyond 100000 in magnitude EOVERFLOW.

Manuscript
fn parse_rat(text String) Result[BigRat, Error] { ... }

rat Function#

Returns numerator / denominator in lowest terms; a zero denominator returns EINVAL.

Manuscript
fn rat(numerator BigInt, denominator BigInt) Result[BigRat, Error] { ... }

rat_of_big_int Function#

Returns an integer as a fraction.

Manuscript
fn rat_of_big_int(value BigInt) BigRat { ... }

rat_of_binary Function#

Returns the exact value mantissa * 2^exponent. A result needing more than 16777216 bits faults.

Manuscript
fn rat_of_binary(mantissa BigInt, exponent Int) BigRat { ... }

rat_of_float Function#

Returns the exact value of a Float as a fraction: 1/2 for 0.5, and 3602879701896397/36028797018963968 for 0.1, which a Float stores inexactly. Returns null for NaN and infinities.

Manuscript
fn rat_of_float(value Float) BigRat? { ... }

rat_of_int Function#

Returns the integer value as a fraction.

Manuscript
fn rat_of_int(value Int) BigRat { ... }