Expand description
Traits for arithmetic.
Modules§
- abs
Abs
,AbsAssign
, andUnsignedAbs
, traits for getting the absolute value of a number.- abs_
diff AbsDiff
andAbsDiffAssign
, traits for getting the absolute value of the difference between two numbers.- add_mul
AddMul
andAddMulAssign
, traits for adding a number and the product of two other numbers.- arithmetic_
checked_ shl ArithmeticCheckedShl
, a trait for left-shifting a number and checking whether the result is representable.- arithmetic_
checked_ shr ArithmeticCheckedShr
, a trait for right-shifting a number and checking whether the result is representable.- binomial_
coefficient - Traits for computing the binomial coefficient of two numbers. There is a trait whose
implementations panic if the result cannot be represented, and a checked trait whose
implementations return
None
in that case:BinomialCoefficient
andCheckedBinomialCoefficient
. - ceiling
Ceiling
andCeilingAssign
, traits for computing the ceiling of a number.- checked_
abs CheckedAbs
, a trait for computing the absolute value of number and checking whether the result is representable.- checked_
add CheckedAdd
, a trait for adding two numbers and checking whether the result is representable.- checked_
add_ mul CheckedAddMul
, a trait for adding a number and the product of two other numbers, and checking whether the result is representable.- checked_
div CheckedDiv
, a trait for dividing two numbers and checking whether the result is representable.- checked_
mul CheckedMul
, a trait for multiplying two numbers and checking whether the result is representable.- checked_
neg CheckedNeg
, a trait for negating a number and checking whether the result is representable.- checked_
next_ power_ of_ 2 CheckedNextPowerOf2
, a trait for getting the next-highest power of 2, if it’s representable.- checked_
pow CheckedPow
, a trait for raising a number to the power of au64
and checking whether the result is representable.- checked_
square CheckedSquare
, a trait for squaring a number and checking whether the result is representable.- checked_
sub CheckedSub
, a trait for subtracting two numbers and checking whether the result is representable.- checked_
sub_ mul CheckedSubMul
, a trait for subtracting the product of two numbers from another number, and checking whether the result is representable.- coprime_
with CoprimeWith
, a trait for determining whether two numbers are coprime.- div_
exact DivExact
andDivExactAssign
, traits for dividing two numbers when it’s known that the division is exact.- div_mod
- Traits for simultaneously finding the quotient and remainder of two numbers, subject to various rounding rules.
- div_
round DivRound
andDivExactAssign
, traits for dividing two numbers according to a specifiedRoundingMode
.- divisible_
by DivisibleBy
, a trait for determining whether one number is divisible by another.- divisible_
by_ power_ of_ 2 DivisibleByPowerOf2
, a trait for determining whether a number is divisible by $2^k$.- eq_mod
EqMod
, a trait for determining whether one number is equal by another modulo a third.- eq_
mod_ power_ of_ 2 EqModPowerOf2
, a trait for determining whether one number is equal to another modulo $2^k$.- extended_
gcd ExtendedGcd
, a trait for computing the GCD (greatest common divisor) of two numbers as well as the coefficients of Bézout’s identity $ax+by=\gcd(a,b)$.- factorial
- Traits for computing the factorial, double factorial, multifactorial, and subfactorial. Each
function has a trait whose implementations panic if the result cannot be represented, and a
checked trait whose implementations return
None
in that case. The traits areFactorial
,DoubleFactorial
,Multifactorial
,Subfactorial
,CheckedFactorial
,CheckedDoubleFactorial
,CheckedMultifactorial
, andCheckedSubfactorial
. - floor
Floor
andFloorAssign
, traits for computing the floor of a number.- gcd
Gcd
andGcdAssign
, traits for computing the GCD (greatest common divisor) of two numbers.- is_
power_ of_ 2 IsPowerOf2
, a trait for determining whether a number is an integer power of 2.- kronecker_
symbol LegendreSymbol
,JacobiSymbol
, andKroneckerSymbol
, traits for computing the Legendre, Jacobi, and Kronecker symbols of two numbers.- lcm
Lcm
,LcmAssign
, andCheckedLcm
, traits for computing the LCM (least common multiple) of two numbers.- log_
base - Traits for taking the base-$b$ logarithm of a number.
- log_
base_ 2 - Traits for taking the base-2 logarithm of a number.
- log_
base_ power_ of_ 2 - Traits for taking the base-$2^k$ logarithm of a number.
- mod_add
ModAdd
andModAddAssign
, traits for adding two numbers modulo another number.- mod_
inverse ModInverse
, a trait for finding the multiplicative inverse of a number modulo another number.- mod_
is_ reduced ModIsReduced
, a trait for checking whether a number is reduced modulo another number.- mod_mul
- Traits for multiplying two numbers modulo another number.
- mod_neg
ModNeg
andModNegAssign
, traits for negating a number modulo another number.- mod_op
- Traits for finding the remainder of two numbers, subject to various rounding rules.
- mod_pow
- Traits for raising a number to a power modulo another number.
- mod_
power_ of_ 2 - Traits for finding the remainder of a number divided by $2^k$, subject to various rounding rules.
- mod_
power_ of_ 2_ add ModPowerOf2Add
andModPowerOf2AddAssign
, traits for adding two numbers modulo $2^k$.- mod_
power_ of_ 2_ inverse ModPowerOf2Inverse
, a trait for finding the multiplicative inverse of a number modulo $2^k$.- mod_
power_ of_ 2_ is_ reduced ModPowerOf2IsReduced
, a trait for checking whether a number is reduced modulo $2^k$.- mod_
power_ of_ 2_ mul ModPowerOf2Mul
andModPowerOf2MulAssign
, traits for multiplying two numbers modulo $2^k$.- mod_
power_ of_ 2_ neg ModPowerOf2Neg
andModPowerOf2NegAssign
, traits for negating a number modulo $2^k$.- mod_
power_ of_ 2_ pow ModPowerOf2Pow
andModPowerOf2PowAssign
, traits for raising a number to a power modulo $2^k$.- mod_
power_ of_ 2_ shl ModPowerOf2Shl
andModPowerOf2ShlAssign
, traits for left-shifting a number modulo $2^k$.- mod_
power_ of_ 2_ shr ModPowerOf2Shr
andModPowerOf2ShrAssign
, traits for right-shifting a number modulo $2^k$.- mod_
power_ of_ 2_ square ModPowerOf2Square
andModPowerOf2SquareAssign
, traits for squaring a number modulo $2^k$.- mod_
power_ of_ 2_ sub ModPowerOf2Sub
andModPowerOf2SubAssign
, traits for subtracting one number by another modulo $2^k$.- mod_shl
ModShl
andModShlAssign
, traits for left-shifting a number modulo another number.- mod_shr
ModShr
andModShrAssign
, traits for right-shifting a number modulo another number.- mod_
square - Traits for squaring a number modulo another number.
- mod_sub
ModSub
andModSubAssign
, traits for subtracting two numbers modulo another number.- neg
NegAssign
, a trait for negating a number in place.- next_
power_ of_ 2 NextPowerOf2
andNextPowerOf2Assign
, traits for getting the next-highest power of 2.- overflowing_
abs OverflowingAbs
andOverflowingAbsAssign
, traits for taking the absolute value of a number and returning a boolean indicating whether an overflow occurred.- overflowing_
add OverflowingAdd
andOverflowingAddAssign
, traits for adding two numbers and returning a boolean indicating whether an overflow occurred.- overflowing_
add_ mul OverflowingAddMul
andOverflowingAddMulAssign
, traits for adding the product of two other numbers to a number and returning a boolean indicating whether an overflow occurred.- overflowing_
div OverflowingDiv
andOverflowingDivAssign
, traits for dividing two numbers and returning a boolean indicating whether an overflow occurred.- overflowing_
mul OverflowingMul
andOverflowingMulAssign
, traits for multiplying two numbers and returning a boolean indicating whether an overflow occurred.- overflowing_
neg OverflowingNeg
andOverflowingNegAssign
, traits for negating a number and returning a boolean indicating whether an overflow occurred.- overflowing_
pow OverflowingPow
andOverflowingPowAssign
, traits for raising a number to a power and returning a boolean indicating whether an overflow occurred.- overflowing_
square OverflowingSquare
andOverflowingSquareAssign
, traits for squaring a number and returning a boolean indicating whether an overflow occurred.- overflowing_
sub OverflowingSub
andOverflowingSubAssign
, traits for subtracting two numbers and returning a boolean indicating whether an overflow occurred.- overflowing_
sub_ mul OverflowingSubMul
andOverflowingSubMulAssign
, traits for subtracting the product of two other numbers from a number and returning a boolean indicating whether an overflow occurred.- parity
Parity
, a trait for determining whether a number is even or odd.- pow
Pow
andPowAssign
, traits for raising a number to a power.- power_
of_ 2 PowerOf2
, a trait for computing a power of 2.- primorial
- Traits for computing the primorial and the product of the first $n$ primes. There is a trait
whose implementations panic if the result cannot be represented, and a checked trait whose
implementations return
None
in that case:Primorial
andCheckedPrimorial
. - reciprocal
Reciprocal
andReciprocalAssign
, traits for computing the reciprocal (multiplicative inverse) of a number.- root
- Traits for taking the $n$th root of a number.
- rotate
RotateLeft
,RotateLeftAssign
,RotateRight
, andRotateRightAssign
, traits for rotating a number’s bits.- round_
to_ multiple RoundToMultiple
andRoundToMultipleAssign
, traits for rounding a number to a multiple of another number.- round_
to_ multiple_ of_ power_ of_ 2 RoundToMultipleOfPowerOf2
andRoundToMultipleOfPowerOf2Assign
, traits for rounding a number to a multiple of a power of 2.- saturating_
abs SaturatingAbs
andSaturatingAbsAssign
, traits for taking the absolute value of a number and saturating at numeric bounds instead of overflowing.- saturating_
add SaturatingAdd
andSaturatingAddAssign
, traits for adding two numbers and saturating at numeric bounds instead of overflowing.- saturating_
add_ mul SaturatingAddMul
andSaturatingAddMulAssign
, traits for adding the product of two numbers to a number and saturating at numeric bounds instead of overflowing.- saturating_
mul SaturatingMul
andSaturatingMulAssign
, traits for multiplying two numbers and saturating at numeric bounds instead of overflowing.- saturating_
neg SaturatingNeg
andSaturatingNegAssign
, traits for negating a number and saturating at numeric bounds instead of overflowing.- saturating_
pow SaturatingPow
andSaturatingPowAssign
, traits for raising a number to a power and saturating at numeric bounds instead of overflowing.- saturating_
square SaturatingSquare
andSaturatingSquareAssign
, traits for squaring a number and saturating at numeric bounds instead of overflowing.- saturating_
sub SaturatingSub
andSaturatingSubAssign
, traits for subtracting two numbers and saturating at numeric bounds instead of overflowing.- saturating_
sub_ mul SaturatingSubMul
andSaturatingSubMulAssign
, traits for subtracting a number by the product of two numbers and saturating at numeric bounds instead of overflowing.- shl_
round ShlRound
andShlRoundAssign
, traits for multiplying a number by a power of 2 and rounding according to a specifiedRoundingMode
.- shr_
round ShrRound
andShrRoundAssign
, traits for dividing a number by a power of 2 and rounding according to a specifiedRoundingMode
.- sign
Sign
, a trait for determining the sign of a number.- sqrt
- Traits for taking the square root of a number.
- square
Square
andSquareAssign
, traits for squaring a number.- sub_mul
SubMul
andSubMulAssign
, traits for subtracting the product of two numbers from a number.- traits
- Various traits for performing arithmetic operations on numbers.
- wrapping_
abs WrappingAbs
andWrappingAbsAssign
, traits for computing the absolute value of a number and wrapping at the boundary of the type.- wrapping_
add WrappingAdd
andWrappingAddAssign
, traits for adding two numbers and wrapping at the boundary of the type.- wrapping_
add_ mul WrappingAddMul
andWrappingAddMulAssign
, traits for adding the product of two numbers to a third and wrapping at the boundary of the type.- wrapping_
div WrappingDiv
andWrappingDivAssign
, traits for dividing two numbers and wrapping at the boundary of the type.- wrapping_
mul WrappingMul
andWrappingMulAssign
, traits for multiplying two numbers and wrapping at the boundary of the type.- wrapping_
neg WrappingNeg
andWrappingNegAssign
for negating a number and wrapping at the boundary of the type.- wrapping_
pow WrappingPow
andWrappingPowAssign
, traits for raising a number to a power and wrapping at the boundary of the type.- wrapping_
square WrappingSquare
andWrappingSquareAssign
, traits for squaring a number and wrapping at the boundary of the type.- wrapping_
sub WrappingSub
andWrappingSubAssign
, traits for subtracting two numbers and wrapping at the boundary of the type.- wrapping_
sub_ mul WrappingSubMul
andWrappingSubMulAssign
, traits for subtracting a number by the product of two other numbers and wrapping at the boundary of the type.- x_
mul_ y_ to_ zz XMulYToZZ
, a trait for multiplying two numbers and returning the result as a double-width number.- xx_
add_ yy_ to_ zz XXAddYYToZZ
, a trait for adding two double-width numbers and returning the result as a double-width number.- xx_
div_ mod_ y_ to_ qr XXDivModYToQR
, a trait for dividing a double-width number by a single-width number and returning the quotient and remainder.- xx_
sub_ yy_ to_ zz XXSubYYToZZ
, a trait for subtracting two double-width numbers and returning the result as a double-width number.- xxx_
add_ yyy_ to_ zzz XXXAddYYYToZZZ
, a trait for adding two triple-width numbers and returning the result as a triple-width number.- xxx_
sub_ yyy_ to_ zzz XXXSubYYYToZZZ
, a trait for subtracting two triple-width numbers and returning the result as a triple-width number.- xxxx_
add_ yyyy_ to_ zzzz XXXXAddYYYYToZZZZ
, a trait for adding two quadruple-width numbers and returning the result as a quadruple-width number.