Expand description
Functions of i64s: greatest common divisor, least common multiple, binomial coefficients, powers, square roots and residues. Each gives None where its result isn’t an i64. Their function objects are the ones that floats and complex numbers use: Gcd, Lcm and Residue from tolerant, whose integer forms ignore the tolerance they hold, and Binom and Pow. A slice form appends results to a vector and reports whether every item fitted. Divisor divides many integers by one, with multiplications in place of division instructions. Where every item has the same divisor, Residue’s slice form divides through FloatDivisor, which multiplies by the divisor’s reciprocal in f64 and vectorizes, for divisors and dividends below 2⁵¹ in magnitude. At types of 16 bits or fewer it multiplies 32-bit integers instead, and it takes Divisor for 64-bit dividends of 2⁵¹ or more.
Gcd, Lcm, Binom, Pow and Residue also take the narrower integer types of compact buffers, u8, i16 and i32, which they compute through these functions. A result that doesn’t fit its type fails. Pow floors a negative power.
Structs§
- Divisor
- A fixed nonzero divisor for dividing many integers. Each division multiplies and shifts, where a division instruction would take several times as long. Setting one up costs more than one division.
Functions§
- binom
- The binomial coefficient C(n, k), with the integer continuations C(n, k) = (-1)^k C(k - n - 1, k) for negative n, and C(n, k) = (-1)^(n - k) C(-k - 1, n - k) for negative k.
Nonewhere the result is outsidei64. - decode
- The value of each cell of
bases.len()digits indigits, in the mixed radix ofbases, as APL’s⊥gives it, with each step wrapped to 64 bits, as BPL’s integer⊥wraps ati64. The first base is never used. Wrapping a value to a narrower width then gives what wrapping each step at that width gives. - encode
- The digits of each of
valuesin the mixed radix ofbases, as APL’s⊤gives them: each value’s digits together, the most significant first. A base of 0 takes all of what remains as its digit.Nonewhere a digit isn’t ani64. - gcd
- The greatest common divisor of x and y, which is never negative.
gcd(0, 0)is 0.Noneonly where it is 2^63, as forgcd(i64::MIN, 0). - lcm
- The least common multiple of x and y, with the sign of x × y. It is 0 where either is 0.
- mask
- The mask whose bitwise and with an integer y gives y’s residue modulo x, where x is a positive power of two: x - 1. In two’s complement, y ∧ (x - 1) is y - x⌊y/x⌋ for every y of every width.
Nonefor any other x. - power
- x^y. 0^0 is 1. A negative y floors the power, as [
wrapped_power] does, withi64’s greatest value for an x of 0.Nonewhere the power doesn’t fit ani64. - residue
- The residue of y modulo x, y - x⌊y/x⌋, which takes the sign of x. A zero x gives y. Every residue fits an
i64.