Skip to main content

Module exact

Module exact 

Source
Expand description

Exact numbers: arbitrary-precision integers and rationals.

These are the two element types that never round. An Ext is J’s “extended” integer, a num-bigint BigInt; a Rat is a pair of them in lowest terms with a positive denominator.

Functions here are the arithmetic only, plus the exactness tests the languages’ type rules turn on — “is this square exact”, “is this power a whole number”. Where an operation has no exact answer the function says so (None) and the caller widens to float; the type rules and the diagnostics live in verb.rs.

Structs§

Rat
A rational number in lowest terms; the denominator is always positive and never zero.

Constants§

MAX_BITS
The largest magnitude a power is allowed to reach, in bits. A bignum power grows without warning — 2 ^ 10000000x is a gigabyte — so the arithmetic refuses rather than exhausts the machine.

Functions§

exact_root
The exact n-th root, when the argument has one. n must be positive.
exact_sqrt
The exact square root, when the argument has one.
ext_binomial
x ! y on whole numbers: the number of ways to choose x things from y. Follows J for the degenerate cases — a negative or oversized x gives 0, and 0 ! y is 1.
ext_factorial
! y on a whole number: the exact factorial. None for a negative argument (a pole) or one large enough to exhaust the machine.
ext_pow
base ^ exp for a whole nonnegative exponent, refusing a result too big to hold.
ext_residue
x | y: y reduced modulo x, the residue taking x’s sign; 0 | y is y.
ext_to_f64
ext_to_i64
f64_exact
A double as the rational it exactly is: mantissa over a power of two.
f64_to_ext
A double as an exact integer, when it is one.
f64_to_rat
A double as the simplest rational within J’s comparison tolerance of it: the first continued-fraction convergent that is close enough. An integral value is exact, so x: 1e30 keeps every digit the double really holds.
rat_gcd
The greatest common divisor of two rationals: gcd(numerators) over lcm(denominators), which is the largest rational dividing both a whole number of times.
rat_lcm
The least common multiple of two rationals, lcm(numerators) over gcd(denominators); zero when either is zero.
rat_residue
x | y on rationals: y - x * <. y % x, as on the reals.
ratio_to_f64
num / den as the nearest double. Dividing the two to_f64s overflows as soon as either half leaves the double range, so the ratio is scaled by its own bit lengths first.

Type Aliases§

Ext
An extended-precision integer (J x).