Module traits

Source
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.
AbsDiffAssign
Replaces a number with the absolute value of its difference with another number.
AddMul
Adds a number and the product of two other numbers.
AddMulAssign
Adds a number and the product of two other numbers, in place.
ArithmeticCheckedShl
Left-shifts a number (multiplies it by a power of 2), returning None if the result is not representable.
ArithmeticCheckedShr
Right-shifts a number (divides it by a power of 2), returning None if the result is not representable.
BinomialCoefficient
Ceiling
Takes the ceiling of a number.
CeilingAssign
Replaces a number with its ceiling.
CeilingDivAssignMod
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).
CeilingDivAssignNegMod
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.
CeilingDivMod
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).
CeilingDivNegMod
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.
CeilingLogBase
Calculates the ceiling of the base-$b$ logarithm of a number.
CeilingLogBase2
Calculates the ceiling of the base-2 logarithm of a number.
CeilingLogBasePowerOf2
Calculates the ceiling of the base-$2^k$ logarithm of a number.
CeilingMod
Divides a number by another number, returning just the remainder. The remainder has the opposite sign as the divisor (second number).
CeilingModAssign
Divides a number by another number, replacing the first number by the remainder. The remainder has the same sign as the divisor (second number).
CeilingModPowerOf2
Divides a number by $2^k$, returning just the remainder. The remainder is non-positive.
CeilingModPowerOf2Assign
Divides a number by $2^k$, replacing the number by the remainder. The remainder is non-positive.
CeilingRoot
Finds the ceiling of the $n$th root of a number.
CeilingRootAssign
Replaces a number with the ceiling of its $n$th root.
CeilingSqrt
Finds the ceiling of the square root of a number.
CeilingSqrtAssign
Replaces a number with the ceiling of its square root.
CheckedAbs
Takes the absolute valie of a number, returning None if the result is not representable.
CheckedAdd
Adds two numbers, returning None if the result is not representable.
CheckedAddMul
Adds a number and the product of two other numbers, returning None if the result is not representable.
CheckedBinomialCoefficient
CheckedDiv
Divides two numbers, returning None if the result is not representable.
CheckedDoubleFactorial
Computes the double factorial of a u64, returning None 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.
CheckedFactorial
Computes the factorial of a u64, returning None if the result is too large to be represented.
CheckedLcm
Calculates the LCM (least common multiple) of two numbers, returning None if the result is not representable.
CheckedLogBase
Calculates the base-$b$ logarithm of a number, or returns None if the number is not a perfect power of $b$.
CheckedLogBase2
Calculates the base-2 logarithm of a number, or returns None if the number is not a perfect power of 2.
CheckedLogBasePowerOf2
Calculates the base-$2^k$ logarithm of a number, or returns None if the number is not a perfect power of $2^k$.
CheckedMul
Multiplies two numbers, returning None if the result is not representable.
CheckedMultifactorial
Computes the $m$-multifactorial of a u64, returning None 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$.
CheckedNeg
Negates a number, returning None if the result is not representable.
CheckedNextPowerOf2
Finds the smallest integer power of 2 greater than or equal to a number, returning None if the result is not representable.
CheckedPow
Raises a number to a power, returning None if the result is not representable.
CheckedPrimorial
CheckedRoot
Finds the $n$th root of a number, returning None if it is not a perfect $n$th power.
CheckedSqrt
Finds the square root of a number, returning None if it is not a perfect square.
CheckedSquare
Squares a number, returning None if the result is not representable.
CheckedSub
Subtracts two numbers, returning None if the result is not representable.
CheckedSubMul
Subtracts a number by the product of two other numbers, returning None if the result is not representable.
CheckedSubfactorial
Computes the subfactorial of a u64, returning None 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.
CoprimeWith
Determines whether two numbers are coprime.
DivAssignMod
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).
DivAssignRem
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.
DivExactAssign
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.
DivRoundAssign
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.
DivisibleBy
Determines whether a number is divisible by another number.
DivisibleByPowerOf2
Determines whether a number is divisible by $2^k$.
DoubleFactorial
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$.
EqModPowerOf2
Determines whether a number is equivalent to another number modulo $2^k$.
ExtendedGcd
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.
FloorAssign
Replaces a number with its floor.
FloorLogBase
Calculates the floor of the base-$b$ logarithm of a number.
FloorLogBase2
Calculates the floor of the base-2 logarithm of a number.
FloorLogBasePowerOf2
Calculates the floor of the base-$2^k$ logarithm of a number.
FloorRoot
Finds the floor of the $n$th root of a number.
FloorRootAssign
Replaces a number with the floor of its $n$th root.
FloorSqrt
Finds the floor of the square root of a number.
FloorSqrtAssign
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.
IsPowerOf2
Determines whether a number is an integer power of 2.
JacobiSymbol
Calculates the Jacobi symbol of two numbers.
KroneckerSymbol
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.
LegendreSymbol
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$.
ModAddAssign
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$.
ModIsReduced
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$.
ModMulAssign
Multiplies two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo $m$.
ModMulPrecomputed
Multiplies two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
ModMulPrecomputedAssign
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$.
ModNegAssign
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$.
ModPowAssign
Raises a number to a power modulo another number $m$, in place. The base must be already reduced modulo $m$.
ModPowPrecomputed
Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
ModPowPrecomputedAssign
Raises a number to a power modulo another number $m$, in place. The base must be already reduced modulo $m$.
ModPowerOf2
Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.
ModPowerOf2Add
Adds two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
ModPowerOf2AddAssign
Adds two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
ModPowerOf2Assign
Divides a number by $2^k$, replacing the number by the remainder. The remainder is non-negative.
ModPowerOf2Inverse
Finds the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.
ModPowerOf2IsReduced
Checks whether a number is reduced modulo $2^k$.
ModPowerOf2Mul
Multiplies two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
ModPowerOf2MulAssign
Multiplies two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
ModPowerOf2Neg
Negates a number modulo $2^k$. The input must be already reduced modulo $2^k$.
ModPowerOf2NegAssign
Negates a number modulo $2^k$ in place. The input must be already reduced modulo $2^k$.
ModPowerOf2Pow
Raises a number to a power modulo $2^k$. The base must be already reduced modulo $2^k$.
ModPowerOf2PowAssign
Raises a number to a power modulo $2^k$, in place. The base must be already reduced modulo $2^k$.
ModPowerOf2Shl
Left-shifts a number (multiplies it by a power of 2) modulo $2^k$. The number must be already reduced modulo $2^k$.
ModPowerOf2ShlAssign
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$.
ModPowerOf2Shr
Right-shifts a number (divides it by a power of 2) modulo $2^k$. The number must be already reduced modulo $2^k$.
ModPowerOf2ShrAssign
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$.
ModPowerOf2Square
Squares a number modulo $2^k$. The input must be already reduced modulo $2^k$.
ModPowerOf2SquareAssign
Squares a number modulo $2^k$ in place. The input must be already reduced modulo $2^k$.
ModPowerOf2Sub
Subtracts two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
ModPowerOf2SubAssign
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$.
ModShlAssign
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$.
ModShrAssign
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$.
ModSquareAssign
Squares a number modulo another number $m$, in place. The input must be already reduced modulo $m$.
ModSquarePrecomputed
Squares a number modulo another number $m$. The input must be already reduced modulo $m$.
ModSquarePrecomputedAssign
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$.
ModSubAssign
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.
NegModAssign
Divides the negative of a number by another number, replacing the first number by the remainder.
NegModPowerOf2
Divides the negative of a number by $2^k$, returning the remainder.
NegModPowerOf2Assign
Divides the negative of a number by $2^k$, replacing the number by the remainder.
NextPowerOf2
Returns the smallest power of 2 greater than or equal to a number. Assumes the result is representable.
NextPowerOf2Assign
Replaces a number with the smallest power of 2 greater than or equal it. Assumes the result is representable.
OverflowingAbs
Takes the absolute value of a number.
OverflowingAbsAssign
Replaces a number with its absolute value.
OverflowingAdd
Adds two numbers.
OverflowingAddAssign
Adds a number to another number in place.
OverflowingAddMul
Adds a number and the product of two other numbers.
OverflowingAddMulAssign
Adds a number and the product of two other numbers, in place.
OverflowingDiv
Divides two numbers.
OverflowingDivAssign
Divides a number by another number in place.
OverflowingMul
Multiplies two numbers.
OverflowingMulAssign
Multiplies a number by another number in place.
OverflowingNeg
Negates a number.
OverflowingNegAssign
Negates a number in place.
OverflowingPow
Raises a number to a power.
OverflowingPowAssign
Raises a number to a power in place.
OverflowingSquare
Squares a number.
OverflowingSquareAssign
Squares a number in place.
OverflowingSub
Subtracts two numbers.
OverflowingSubAssign
Subtracts a number by another number in place.
OverflowingSubMul
Subtracts a number by the product of two other numbers.
OverflowingSubMulAssign
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.
PowerOf2
Raises 2 to a power.
Primorial
Reciprocal
Finds the reciprocal (multiplicative inverse) of a number.
ReciprocalAssign
Replaces a number with its reciprocal (multiplicative inverse).
RemPowerOf2
Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the number.
RemPowerOf2Assign
Divides a number by $2^k$, replacing the number by the remainder. The remainder has the same sign as the number.
RootAssignRem
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.
RotateLeft
Rotates a number left, inserting the leftmost bits into the right end.
RotateLeftAssign
Rotates a number left, inserting the leftmost bits into the right end, in place.
RotateRight
Rotates a number right, inserting the leftmost bits into the left end.
RotateRightAssign
Rotates a number right, inserting the leftmost bits into the left end, in place.
RoundToMultiple
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.
RoundToMultipleAssign
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.
RoundToMultipleOfPowerOf2
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.
RoundToMultipleOfPowerOf2Assign
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.
SaturatingAbs
Takes the absolute value of a number, saturating at the numeric bounds instead of overflowing.
SaturatingAbsAssign
Replaces a number with its absolute value, saturating at the numeric bounds instead of overflowing.
SaturatingAdd
Adds two numbers, saturating at the numeric bounds instead of overflowing.
SaturatingAddAssign
Add a number to another number in place, saturating at the numeric bounds instead of overflowing.
SaturatingAddMul
Adds a number and the product of two other numbers, saturating at the numeric bounds instead of overflowing.
SaturatingAddMulAssign
Adds a number and the product of two other numbers in place, saturating at the numeric bounds instead of overflowing.
SaturatingMul
Multiplies two numbers, saturating at the numeric bounds instead of overflowing.
SaturatingMulAssign
Multiplies a number by another number in place, saturating at the numeric bounds instead of overflowing.
SaturatingNeg
Negates a number, saturating at the numeric bounds instead of overflowing.
SaturatingNegAssign
Negates a number in place, saturating at the numeric bounds instead of overflowing.
SaturatingPow
Raises a number to a power, saturating at the numeric bounds instead of overflowing.
SaturatingPowAssign
Raises a number to a power in place, saturating at the numeric bounds instead of overflowing.
SaturatingSquare
Squares a number, saturating at the numeric bounds instead of overflowing.
SaturatingSquareAssign
Squares a number in place, saturating at the numeric bounds instead of overflowing.
SaturatingSub
Subtracts two numbers, saturating at the numeric bounds instead of overflowing.
SaturatingSubAssign
Subtracts a number by another number in place, saturating at the numeric bounds instead of overflowing.
SaturatingSubMul
Subtracts a number by the product of two other numbers, saturating at the numeric bounds instead of overflowing.
SaturatingSubMulAssign
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.
ShlRoundAssign
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.
ShrRoundAssign
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, or Less, depending on whether a number is positive, zero, or negative, respectively.
Sqrt
Takes the square root of a number.
SqrtAssign
Replaces a number with its square root.
SqrtAssignRem
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.
SquareAssign
Replaces a number with its square.
SubMul
Subtracts a number by the product of two other numbers.
SubMulAssign
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.
UnsignedAbs
Takes the absolute value of a number and converts to the unsigned equivalent.
WrappingAbs
Takes the absolute value of a number, wrapping around at the boundary of the type.
WrappingAbsAssign
Replaces a number with its absolute value, wrapping around at the boundary of the type.
WrappingAdd
Adds two numbers, wrapping around at the boundary of the type.
WrappingAddAssign
Adds a number to another number in place, wrapping around at the boundary of the type.
WrappingAddMul
Adds a number and the product of two other numbers, wrapping around at the boundary of the type.
WrappingAddMulAssign
Adds a number and the product of two other numbers, in place, wrapping around at the boundary of the type.
WrappingDiv
Divides a number by another number, wrapping around at the boundary of the type.
WrappingDivAssign
Divides a number by another number in place, wrapping around at the boundary of the type.
WrappingMul
Multiplies two numbers, wrapping around at the boundary of the type.
WrappingMulAssign
Multiplies a number by another number in place, wrapping around at the boundary of the type.
WrappingNeg
Negates a number, wrapping around at the boundary of the type.
WrappingNegAssign
Negates a number in place, wrapping around at the boundary of the type.
WrappingPow
Raises a number to a power, wrapping around at the boundary of the type.
WrappingPowAssign
Raises a number to a power in place, wrapping around at the boundary of the type.
WrappingSquare
Squares a number, wrapping around at the boundary of the type.
WrappingSquareAssign
Squares a number in place, wrapping around at the boundary of the type.
WrappingSub
Subtracts two numbers, wrapping around at the boundary of the type.
WrappingSubAssign
Subtracts a number by another number in place, wrapping around at the boundary of the type.
WrappingSubMul
Subtracts a number by the product of two other numbers, wrapping around at the boundary of the type.
WrappingSubMulAssign
Subtracts a number by the product of two other numbers, in place, wrapping around at the boundary of the type.
XMulYToZZ
Multiplies two numbers, returning the product as a pair of Self values.
XXAddYYToZZ
Adds two numbers, each composed of two Self values, returning the sum as a pair of Self values.
XXDivModYToQR
Computes the quotient and remainder of two numbers. The first is composed of two Self values, and the second of a single one.
XXSubYYToZZ
Subtracts two numbers, each composed of two Self values, returing the difference as a pair of Self values.
XXXAddYYYToZZZ
Adds two numbers, each composed of three Self values, returning the sum as a triple of Self values.
XXXSubYYYToZZZ
Subtracts two numbers, each composed of three Self values, returing the difference as a triple of Self values.
XXXXAddYYYYToZZZZ
Adds two numbers, each composed of four Self values, returning the sum as a quadruple of Self values.