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 ^ 10000000xis a gigabyte — so the arithmetic refuses rather than exhausts the machine.
Functions§
- exact_
root - The exact
n-th root, when the argument has one.nmust be positive. - exact_
sqrt - The exact square root, when the argument has one.
- ext_
binomial x ! yon 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, and0 ! yis 1.- ext_
factorial ! yon a whole number: the exact factorial. None for a negative argument (a pole) or one large enough to exhaust the machine.- ext_pow
base ^ expfor 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 | yis 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: 1e30keeps 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)overgcd(denominators); zero when either is zero. - rat_
residue x | yon rationals:y - x * <. y % x, as on the reals.- ratio_
to_ f64 num / denas the nearest double. Dividing the twoto_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).