Expand description
Various traits for performing arithmetic operations on numbers.
Traits§
- Abs
- Takes the absolute value of a number. Assumes that the number has a representable absolute number.
- AbsAssign
- Replaces a number with its absolute value. Assumes that the number has a representable absolute number.
- AbsDiff
- Subtracts two numbers and takes the absolute value of the difference.
- AbsDiff
Assign - Replaces a number with the absolute value of its difference with another number.
- AddMul
- Adds a number and the product of two other numbers.
- AddMul
Assign - Adds a number and the product of two other numbers, in place.
- Arithmetic
Checked Shl - Left-shifts a number (multiplies it by a power of 2), returning
None
if the result is not representable. - Arithmetic
Checked Shr - Right-shifts a number (divides it by a power of 2), returning
None
if the result is not representable. - Binomial
Coefficient - Ceiling
- Takes the ceiling of a number.
- Ceiling
Assign - Replaces a number with its ceiling.
- Ceiling
DivAssign Mod - Divides a number by another number in place, taking the quotient and returning the remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign of the divisor (second input).
- Ceiling
DivAssign NegMod - Divides a number by another number in place, taking the ceiling of the quotient and returning the remainder of the negative of the first number divided by the second.
- Ceiling
DivMod - Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign as the divisor (second input).
- Ceiling
DivNeg Mod - Divides a number by another number, returning the ceiling of the quotient and the remainder of the negative of the first number divided by the second.
- Ceiling
LogBase - Calculates the ceiling of the base-$b$ logarithm of a number.
- Ceiling
LogBase2 - Calculates the ceiling of the base-2 logarithm of a number.
- Ceiling
LogBase Power Of2 - Calculates the ceiling of the base-$2^k$ logarithm of a number.
- Ceiling
Mod - Divides a number by another number, returning just the remainder. The remainder has the opposite sign as the divisor (second number).
- Ceiling
ModAssign - Divides a number by another number, replacing the first number by the remainder. The remainder has the same sign as the divisor (second number).
- Ceiling
ModPower Of2 - Divides a number by $2^k$, returning just the remainder. The remainder is non-positive.
- Ceiling
ModPower Of2Assign - Divides a number by $2^k$, replacing the number by the remainder. The remainder is non-positive.
- Ceiling
Root - Finds the ceiling of the $n$th root of a number.
- Ceiling
Root Assign - Replaces a number with the ceiling of its $n$th root.
- Ceiling
Sqrt - Finds the ceiling of the square root of a number.
- Ceiling
Sqrt Assign - Replaces a number with the ceiling of its square root.
- Checked
Abs - Takes the absolute valie of a number, returning
None
if the result is not representable. - Checked
Add - Adds two numbers, returning
None
if the result is not representable. - Checked
AddMul - Adds a number and the product of two other numbers, returning
None
if the result is not representable. - Checked
Binomial Coefficient - Checked
Div - Divides two numbers, returning
None
if the result is not representable. - Checked
Double Factorial - Computes the double factorial of a
u64
, returningNone
if the result is too large to be represented. The double factorial of a non-negative integer is the product of all the positive integers that are less than or equal to it and have the same parity as it. - Checked
Factorial - Computes the factorial of a
u64
, returningNone
if the result is too large to be represented. - Checked
Lcm - Calculates the LCM (least common multiple) of two numbers, returning
None
if the result is not representable. - Checked
LogBase - Calculates the base-$b$ logarithm of a number, or returns
None
if the number is not a perfect power of $b$. - Checked
LogBase2 - Calculates the base-2 logarithm of a number, or returns
None
if the number is not a perfect power of 2. - Checked
LogBase Power Of2 - Calculates the base-$2^k$ logarithm of a number, or returns
None
if the number is not a perfect power of $2^k$. - Checked
Mul - Multiplies two numbers, returning
None
if the result is not representable. - Checked
Multifactorial - Computes the $m$-multifactorial of a
u64
, returningNone
if the result is too large to be represented. The $m$-multifactorial of a non-negative integer $n$ is the product of all integers $k$ such that $0<k\leq n$ and $k\equiv n \pmod m$. - Checked
Neg - Negates a number, returning
None
if the result is not representable. - Checked
Next Power Of2 - Finds the smallest integer power of 2 greater than or equal to a number, returning
None
if the result is not representable. - Checked
Pow - Raises a number to a power, returning
None
if the result is not representable. - Checked
Primorial - Checked
Root - Finds the $n$th root of a number, returning
None
if it is not a perfect $n$th power. - Checked
Sqrt - Finds the square root of a number, returning
None
if it is not a perfect square. - Checked
Square - Squares a number, returning
None
if the result is not representable. - Checked
Sub - Subtracts two numbers, returning
None
if the result is not representable. - Checked
SubMul - Subtracts a number by the product of two other numbers, returning
None
if the result is not representable. - Checked
Subfactorial - Computes the subfactorial of a
u64
, returningNone
if the result is too large to be represented. The subfactorial of a non-negative integer $n$ counts the number of derangements of $n$ elements, which are the permutations in which no element is fixed. - Coprime
With - Determines whether two numbers are coprime.
- DivAssign
Mod - Divides a number by another number in place, returning the remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the divisor (second input).
- DivAssign
Rem - Divides a number by another number in place, returning the remainder. The quotient is rounded towards zero, and the remainder has the same sign as the dividend (first input).
- DivExact
- Divides two numbers, assuming the first exactly divides the second.
- DivExact
Assign - Divides a number by another number in place, assuming the first exactly divides the second.
- DivMod
- Divides two numbers, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the divisor (second input).
- DivRem
- Divides two numbers, returning the quotient and remainder. The quotient is rounded towards zero, and the remainder has the same sign as the dividend (first input).
- DivRound
- Divides a number by another number and rounds according to a specified rounding mode. An
Ordering
is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. - DivRound
Assign - Divides a number by another number in place and rounds according to a specified rounding mode.
An
Ordering
is returned, indicating whether the assigned value is less than, equal to, or greater than the exact value. - Divisible
By - Determines whether a number is divisible by another number.
- Divisible
ByPower Of2 - Determines whether a number is divisible by $2^k$.
- Double
Factorial - Computes the double factorial of a
u64
. The double factorial of a non-negative integer is the product of all the positive integers that are less than or equal to it and have the same parity as it. - EqMod
- Determines whether a number is equivalent to another number modulo $m$.
- EqMod
Power Of2 - Determines whether a number is equivalent to another number modulo $2^k$.
- Extended
Gcd - Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.
- Factorial
- Computes the factorial of a
u64
. - Floor
- Takes the floor of a number.
- Floor
Assign - Replaces a number with its floor.
- Floor
LogBase - Calculates the floor of the base-$b$ logarithm of a number.
- Floor
LogBase2 - Calculates the floor of the base-2 logarithm of a number.
- Floor
LogBase Power Of2 - Calculates the floor of the base-$2^k$ logarithm of a number.
- Floor
Root - Finds the floor of the $n$th root of a number.
- Floor
Root Assign - Replaces a number with the floor of its $n$th root.
- Floor
Sqrt - Finds the floor of the square root of a number.
- Floor
Sqrt Assign - Replaces a number with the floor of its square root.
- Gcd
- Calculates the GCD (greatest common divisor) of two numbers.
- GcdAssign
- Replaces a number with the GCD (greatest common divisor) of it and another number.
- IsPower
Of2 - Determines whether a number is an integer power of 2.
- Jacobi
Symbol - Calculates the Jacobi symbol of two numbers.
- Kronecker
Symbol - Calculates the Kronecker symbol of two numbers.
- Lcm
- Calculates the LCM (least common multiple) of two numbers.
- LcmAssign
- Replaces a number with the LCM (least common multiple) of it and another number.
- Legendre
Symbol - Calculates the Legendre symbol of two numbers. Typically the implementations will be identical
to those of
JacobiSymbol
. - Ln
- Takes the natural logarithm of a number.
- Mod
- Divides a number by another number, returning just the remainder. The remainder has the same sign as the divisor (second number).
- ModAdd
- Adds two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
- ModAdd
Assign - Adds two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo $m$.
- ModAssign
- Divides a number by another number, replacing the first number by the remainder. The remainder has the same sign as the divisor (second number).
- ModInverse
- Finds the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
- ModIs
Reduced - Checks whether a number is reduced modulo another number $m$.
- ModMul
- Multiplies two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
- ModMul
Assign - Multiplies two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo $m$.
- ModMul
Precomputed - Multiplies two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
- ModMul
Precomputed Assign - Multiplies two numbers modulo a third number $m$, in place.The inputs must be already reduced modulo $m$.
- ModNeg
- Negates a number modulo another number $m$. The input must be already reduced modulo $m$.
- ModNeg
Assign - Negates a number modulo another number $m$, in place. The input must be already reduced modulo $m$.
- ModPow
- Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
- ModPow
Assign - Raises a number to a power modulo another number $m$, in place. The base must be already reduced modulo $m$.
- ModPow
Precomputed - Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
- ModPow
Precomputed Assign - Raises a number to a power modulo another number $m$, in place. The base must be already reduced modulo $m$.
- ModPower
Of2 - Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.
- ModPower
Of2Add - Adds two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
- ModPower
Of2Add Assign - Adds two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
- ModPower
Of2Assign - Divides a number by $2^k$, replacing the number by the remainder. The remainder is non-negative.
- ModPower
Of2Inverse - Finds the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.
- ModPower
Of2Is Reduced - Checks whether a number is reduced modulo $2^k$.
- ModPower
Of2Mul - Multiplies two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
- ModPower
Of2Mul Assign - Multiplies two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
- ModPower
Of2Neg - Negates a number modulo $2^k$. The input must be already reduced modulo $2^k$.
- ModPower
Of2Neg Assign - Negates a number modulo $2^k$ in place. The input must be already reduced modulo $2^k$.
- ModPower
Of2Pow - Raises a number to a power modulo $2^k$. The base must be already reduced modulo $2^k$.
- ModPower
Of2Pow Assign - Raises a number to a power modulo $2^k$, in place. The base must be already reduced modulo $2^k$.
- ModPower
Of2Shl - Left-shifts a number (multiplies it by a power of 2) modulo $2^k$. The number must be already reduced modulo $2^k$.
- ModPower
Of2Shl Assign - Left-shifts a number (multiplies it by a power of 2) modulo $2^k$, in place. The number must be already reduced modulo $2^k$.
- ModPower
Of2Shr - Right-shifts a number (divides it by a power of 2) modulo $2^k$. The number must be already reduced modulo $2^k$.
- ModPower
Of2Shr Assign - Right-shifts a number (divides it by a power of 2) modulo $2^k$, in place. The number must be already reduced modulo $2^k$.
- ModPower
Of2Square - Squares a number modulo $2^k$. The input must be already reduced modulo $2^k$.
- ModPower
Of2Square Assign - Squares a number modulo $2^k$ in place. The input must be already reduced modulo $2^k$.
- ModPower
Of2Sub - Subtracts two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
- ModPower
Of2Sub Assign - Subtracts two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
- ModShl
- Left-shifts a number (multiplies it by a power of 2) modulo another number $m$. The number must be already reduced modulo $m$.
- ModShl
Assign - Left-shifts a number (multiplies it by a power of 2) modulo another number $m$, in place. The number must be already reduced modulo $m$.
- ModShr
- Left-shifts a number (divides it by a power of 2) modulo another number $m$. The number must be already reduced modulo $m$.
- ModShr
Assign - Left-shifts a number (divides it by a power of 2) modulo another number $m$, in place. The number must be already reduced modulo $m$.
- ModSquare
- Squares a number modulo another number $m$. The input must be already reduced modulo $m$.
- ModSquare
Assign - Squares a number modulo another number $m$, in place. The input must be already reduced modulo $m$.
- ModSquare
Precomputed - Squares a number modulo another number $m$. The input must be already reduced modulo $m$.
- ModSquare
Precomputed Assign - Squares a number modulo another number $m$, in place. The input must be already reduced modulo $m$.
- ModSub
- Adds two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
- ModSub
Assign - Adds two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo $m$.
- Multifactorial
- Computes the $m$-multifactorial of a
u64
. The $m$-multifactorial of a non-negative integer $n$ is the product of all integers $k$ such that $0<k\leq n$ and $k\equiv n \pmod m$. - NegAssign
- Replaces a number with its negative. Assumes the result is representable.
- NegMod
- Divides the negative of a number by another number, returning the remainder.
- NegMod
Assign - Divides the negative of a number by another number, replacing the first number by the remainder.
- NegMod
Power Of2 - Divides the negative of a number by $2^k$, returning the remainder.
- NegMod
Power Of2Assign - Divides the negative of a number by $2^k$, replacing the number by the remainder.
- Next
Power Of2 - Returns the smallest power of 2 greater than or equal to a number. Assumes the result is representable.
- Next
Power Of2Assign - Replaces a number with the smallest power of 2 greater than or equal it. Assumes the result is representable.
- Overflowing
Abs - Takes the absolute value of a number.
- Overflowing
AbsAssign - Replaces a number with its absolute value.
- Overflowing
Add - Adds two numbers.
- Overflowing
AddAssign - Adds a number to another number in place.
- Overflowing
AddMul - Adds a number and the product of two other numbers.
- Overflowing
AddMul Assign - Adds a number and the product of two other numbers, in place.
- Overflowing
Div - Divides two numbers.
- Overflowing
DivAssign - Divides a number by another number in place.
- Overflowing
Mul - Multiplies two numbers.
- Overflowing
MulAssign - Multiplies a number by another number in place.
- Overflowing
Neg - Negates a number.
- Overflowing
NegAssign - Negates a number in place.
- Overflowing
Pow - Raises a number to a power.
- Overflowing
PowAssign - Raises a number to a power in place.
- Overflowing
Square - Squares a number.
- Overflowing
Square Assign - Squares a number in place.
- Overflowing
Sub - Subtracts two numbers.
- Overflowing
SubAssign - Subtracts a number by another number in place.
- Overflowing
SubMul - Subtracts a number by the product of two other numbers.
- Overflowing
SubMul Assign - Subtracts a number by the product of two other numbers, in place.
- Parity
- Determines whether a number is even or odd.
- Pow
- Raises a number to a power. Assumes the result is representable.
- PowAssign
- Raises a number to a power in place. Assumes the result is representable.
- Power
Of2 - Raises 2 to a power.
- Primorial
- Reciprocal
- Finds the reciprocal (multiplicative inverse) of a number.
- Reciprocal
Assign - Replaces a number with its reciprocal (multiplicative inverse).
- RemPower
Of2 - Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the number.
- RemPower
Of2Assign - Divides a number by $2^k$, replacing the number by the remainder. The remainder has the same sign as the number.
- Root
Assign Rem - Replaces a number with the floor of its $n$th root, returning the remainder.
- RootRem
- Finds the floor of the $n$th root of a number, returning both the root and the remainder.
- Rotate
Left - Rotates a number left, inserting the leftmost bits into the right end.
- Rotate
Left Assign - Rotates a number left, inserting the leftmost bits into the right end, in place.
- Rotate
Right - Rotates a number right, inserting the leftmost bits into the left end.
- Rotate
Right Assign - Rotates a number right, inserting the leftmost bits into the left end, in place.
- Round
ToMultiple - Rounds a number to a multiple of another number, according to a specified rounding mode. An
Ordering
is also returned, indicating whether the returned value is less than, equal to, or greater than the original value. - Round
ToMultiple Assign - Rounds a number to a multiple of another number in place, according to a specified rounding
mode.
Ordering
is returned, indicating whether the returned value is less than, equal to, or greater than the original value. - Round
ToMultiple OfPower Of2 - Rounds a number to a multiple of $2^k$, according to a specified rounding mode. An
Ordering
is also returned, indicating whether the returned value is less than, equal to, or greater than the original value. - Round
ToMultiple OfPower Of2Assign - Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode. An
Ordering
is returned, indicating whether the returned value is less than, equal to, or greater than the original value. - Saturating
Abs - Takes the absolute value of a number, saturating at the numeric bounds instead of overflowing.
- Saturating
AbsAssign - Replaces a number with its absolute value, saturating at the numeric bounds instead of overflowing.
- Saturating
Add - Adds two numbers, saturating at the numeric bounds instead of overflowing.
- Saturating
AddAssign - Add a number to another number in place, saturating at the numeric bounds instead of overflowing.
- Saturating
AddMul - Adds a number and the product of two other numbers, saturating at the numeric bounds instead of overflowing.
- Saturating
AddMul Assign - Adds a number and the product of two other numbers in place, saturating at the numeric bounds instead of overflowing.
- Saturating
Mul - Multiplies two numbers, saturating at the numeric bounds instead of overflowing.
- Saturating
MulAssign - Multiplies a number by another number in place, saturating at the numeric bounds instead of overflowing.
- Saturating
Neg - Negates a number, saturating at the numeric bounds instead of overflowing.
- Saturating
NegAssign - Negates a number in place, saturating at the numeric bounds instead of overflowing.
- Saturating
Pow - Raises a number to a power, saturating at the numeric bounds instead of overflowing.
- Saturating
PowAssign - Raises a number to a power in place, saturating at the numeric bounds instead of overflowing.
- Saturating
Square - Squares a number, saturating at the numeric bounds instead of overflowing.
- Saturating
Square Assign - Squares a number in place, saturating at the numeric bounds instead of overflowing.
- Saturating
Sub - Subtracts two numbers, saturating at the numeric bounds instead of overflowing.
- Saturating
SubAssign - Subtracts a number by another number in place, saturating at the numeric bounds instead of overflowing.
- Saturating
SubMul - Subtracts a number by the product of two other numbers, saturating at the numeric bounds instead of overflowing.
- Saturating
SubMul Assign - Subtracts a number by the product of two other numbers in place, saturating at the numeric bounds instead of overflowing.
- ShlRound
- Left-shifts a number (multiplies it by a power of 2), rounding the result according to a
specified rounding mode. An
Ordering
is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. - ShlRound
Assign - Left-shifts a number (multiplies it by a power of 2) in place, rounding the result according to
a specified rounding mode. An
Ordering
is also returned, indicating whether the assigned value is less than, equal to, or greater than the exact value. - ShrRound
- Right-shifts a number (divides it by a power of 2), rounding the result according to a specified
rounding mode. An
Ordering
is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. - ShrRound
Assign - Right-shifts a number (divides it by a power of 2) in place, rounding the result according to a
specified rounding mode. An
Ordering
is also returned, indicating whether the assigned value is less than, equal to, or greater than the exact value. - Sign
- Returns
Greater
,Equal
, orLess
, depending on whether a number is positive, zero, or negative, respectively. - Sqrt
- Takes the square root of a number.
- Sqrt
Assign - Replaces a number with its square root.
- Sqrt
Assign Rem - Replaces a number with the floor of its square root, returning the remainder.
- SqrtRem
- Finds the floor of the square root of a number, returning both the root and the remainder.
- Square
- Squares a number.
- Square
Assign - Replaces a number with its square.
- SubMul
- Subtracts a number by the product of two other numbers.
- SubMul
Assign - Subtracts a number by the product of two other numbers, in place.
- Subfactorial
- Computes the subfactorial of a
u64
. The subfactorial of a non-negative integer $n$ counts the number of derangements of $n$ elements, which are the permutations in which no element is fixed. - Unsigned
Abs - Takes the absolute value of a number and converts to the unsigned equivalent.
- Wrapping
Abs - Takes the absolute value of a number, wrapping around at the boundary of the type.
- Wrapping
AbsAssign - Replaces a number with its absolute value, wrapping around at the boundary of the type.
- Wrapping
Add - Adds two numbers, wrapping around at the boundary of the type.
- Wrapping
AddAssign - Adds a number to another number in place, wrapping around at the boundary of the type.
- Wrapping
AddMul - Adds a number and the product of two other numbers, wrapping around at the boundary of the type.
- Wrapping
AddMul Assign - Adds a number and the product of two other numbers, in place, wrapping around at the boundary of the type.
- Wrapping
Div - Divides a number by another number, wrapping around at the boundary of the type.
- Wrapping
DivAssign - Divides a number by another number in place, wrapping around at the boundary of the type.
- Wrapping
Mul - Multiplies two numbers, wrapping around at the boundary of the type.
- Wrapping
MulAssign - Multiplies a number by another number in place, wrapping around at the boundary of the type.
- Wrapping
Neg - Negates a number, wrapping around at the boundary of the type.
- Wrapping
NegAssign - Negates a number in place, wrapping around at the boundary of the type.
- Wrapping
Pow - Raises a number to a power, wrapping around at the boundary of the type.
- Wrapping
PowAssign - Raises a number to a power in place, wrapping around at the boundary of the type.
- Wrapping
Square - Squares a number, wrapping around at the boundary of the type.
- Wrapping
Square Assign - Squares a number in place, wrapping around at the boundary of the type.
- Wrapping
Sub - Subtracts two numbers, wrapping around at the boundary of the type.
- Wrapping
SubAssign - Subtracts a number by another number in place, wrapping around at the boundary of the type.
- Wrapping
SubMul - Subtracts a number by the product of two other numbers, wrapping around at the boundary of the type.
- Wrapping
SubMul Assign - Subtracts a number by the product of two other numbers, in place, wrapping around at the boundary of the type.
- XMulY
ToZZ - Multiplies two numbers, returning the product as a pair of
Self
values. - XXAddYY
ToZZ - Adds two numbers, each composed of two
Self
values, returning the sum as a pair ofSelf
values. - XXDiv
ModY ToQR - Computes the quotient and remainder of two numbers. The first is composed of two
Self
values, and the second of a single one. - XXSubYY
ToZZ - Subtracts two numbers, each composed of two
Self
values, returing the difference as a pair ofSelf
values. - XXXAddYYY
ToZZZ - Adds two numbers, each composed of three
Self
values, returning the sum as a triple ofSelf
values. - XXXSubYYY
ToZZZ - Subtracts two numbers, each composed of three
Self
values, returing the difference as a triple ofSelf
values. - XXXX
AddYYYY ToZZZZ - Adds two numbers, each composed of four
Self
values, returning the sum as a quadruple ofSelf
values.