Expand description
Traits for arithmetic.
Modules§
- abs
Abs,AbsAssign, andUnsignedAbs, traits for getting the absolute value of a number.- abs_
diff AbsDiffandAbsDiffAssign, traits for getting the absolute value of the difference between two numbers.- add_mul
AddMulandAddMulAssign, 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
Nonein that case:BinomialCoefficientandCheckedBinomialCoefficient. - ceiling
CeilingandCeilingAssign, 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 au64and 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 DivExactandDivExactAssign, 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 DivRoundandDivExactAssign, 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
Nonein that case. The traits areFactorial,DoubleFactorial,Multifactorial,Subfactorial,CheckedFactorial,CheckedDoubleFactorial,CheckedMultifactorial, andCheckedSubfactorial. - floor
FloorandFloorAssign, traits for computing the floor of a number.- gcd
GcdandGcdAssign, 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
ModAddandModAddAssign, 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
ModNegandModNegAssign, 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 ModPowerOf2AddandModPowerOf2AddAssign, 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 ModPowerOf2MulandModPowerOf2MulAssign, traits for multiplying two numbers modulo $2^k$.- mod_
power_ of_ 2_ neg ModPowerOf2NegandModPowerOf2NegAssign, traits for negating a number modulo $2^k$.- mod_
power_ of_ 2_ pow ModPowerOf2PowandModPowerOf2PowAssign, traits for raising a number to a power modulo $2^k$.- mod_
power_ of_ 2_ shl ModPowerOf2ShlandModPowerOf2ShlAssign, traits for left-shifting a number modulo $2^k$.- mod_
power_ of_ 2_ shr ModPowerOf2ShrandModPowerOf2ShrAssign, traits for right-shifting a number modulo $2^k$.- mod_
power_ of_ 2_ square ModPowerOf2SquareandModPowerOf2SquareAssign, traits for squaring a number modulo $2^k$.- mod_
power_ of_ 2_ sub ModPowerOf2SubandModPowerOf2SubAssign, traits for subtracting one number by another modulo $2^k$.- mod_shl
ModShlandModShlAssign, traits for left-shifting a number modulo another number.- mod_shr
ModShrandModShrAssign, traits for right-shifting a number modulo another number.- mod_
square - Traits for squaring a number modulo another number.
- mod_sub
ModSubandModSubAssign, traits for subtracting two numbers modulo another number.- neg
NegAssign, a trait for negating a number in place.- next_
power_ of_ 2 NextPowerOf2andNextPowerOf2Assign, traits for getting the next-highest power of 2.- overflowing_
abs OverflowingAbsandOverflowingAbsAssign, traits for taking the absolute value of a number and returning a boolean indicating whether an overflow occurred.- overflowing_
add OverflowingAddandOverflowingAddAssign, traits for adding two numbers and returning a boolean indicating whether an overflow occurred.- overflowing_
add_ mul OverflowingAddMulandOverflowingAddMulAssign, traits for adding the product of two other numbers to a number and returning a boolean indicating whether an overflow occurred.- overflowing_
div OverflowingDivandOverflowingDivAssign, traits for dividing two numbers and returning a boolean indicating whether an overflow occurred.- overflowing_
mul OverflowingMulandOverflowingMulAssign, traits for multiplying two numbers and returning a boolean indicating whether an overflow occurred.- overflowing_
neg OverflowingNegandOverflowingNegAssign, traits for negating a number and returning a boolean indicating whether an overflow occurred.- overflowing_
pow OverflowingPowandOverflowingPowAssign, traits for raising a number to a power and returning a boolean indicating whether an overflow occurred.- overflowing_
square OverflowingSquareandOverflowingSquareAssign, traits for squaring a number and returning a boolean indicating whether an overflow occurred.- overflowing_
sub OverflowingSubandOverflowingSubAssign, traits for subtracting two numbers and returning a boolean indicating whether an overflow occurred.- overflowing_
sub_ mul OverflowingSubMulandOverflowingSubMulAssign, 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
PowandPowAssign, 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
Nonein that case:PrimorialandCheckedPrimorial. - reciprocal
ReciprocalandReciprocalAssign, 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 RoundToMultipleandRoundToMultipleAssign, traits for rounding a number to a multiple of another number.- round_
to_ multiple_ of_ power_ of_ 2 RoundToMultipleOfPowerOf2andRoundToMultipleOfPowerOf2Assign, traits for rounding a number to a multiple of a power of 2.- saturating_
abs SaturatingAbsandSaturatingAbsAssign, traits for taking the absolute value of a number and saturating at numeric bounds instead of overflowing.- saturating_
add SaturatingAddandSaturatingAddAssign, traits for adding two numbers and saturating at numeric bounds instead of overflowing.- saturating_
add_ mul SaturatingAddMulandSaturatingAddMulAssign, traits for adding the product of two numbers to a number and saturating at numeric bounds instead of overflowing.- saturating_
mul SaturatingMulandSaturatingMulAssign, traits for multiplying two numbers and saturating at numeric bounds instead of overflowing.- saturating_
neg SaturatingNegandSaturatingNegAssign, traits for negating a number and saturating at numeric bounds instead of overflowing.- saturating_
pow SaturatingPowandSaturatingPowAssign, traits for raising a number to a power and saturating at numeric bounds instead of overflowing.- saturating_
square SaturatingSquareandSaturatingSquareAssign, traits for squaring a number and saturating at numeric bounds instead of overflowing.- saturating_
sub SaturatingSubandSaturatingSubAssign, traits for subtracting two numbers and saturating at numeric bounds instead of overflowing.- saturating_
sub_ mul SaturatingSubMulandSaturatingSubMulAssign, traits for subtracting a number by the product of two numbers and saturating at numeric bounds instead of overflowing.- shl_
round ShlRoundandShlRoundAssign, traits for multiplying a number by a power of 2 and rounding according to a specifiedRoundingMode.- shr_
round ShrRoundandShrRoundAssign, 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
SquareandSquareAssign, traits for squaring a number.- sub_mul
SubMulandSubMulAssign, traits for subtracting the product of two numbers from a number.- traits
- Various traits for performing arithmetic operations on numbers.
- wrapping_
abs WrappingAbsandWrappingAbsAssign, traits for computing the absolute value of a number and wrapping at the boundary of the type.- wrapping_
add WrappingAddandWrappingAddAssign, traits for adding two numbers and wrapping at the boundary of the type.- wrapping_
add_ mul WrappingAddMulandWrappingAddMulAssign, traits for adding the product of two numbers to a third and wrapping at the boundary of the type.- wrapping_
div WrappingDivandWrappingDivAssign, traits for dividing two numbers and wrapping at the boundary of the type.- wrapping_
mul WrappingMulandWrappingMulAssign, traits for multiplying two numbers and wrapping at the boundary of the type.- wrapping_
neg WrappingNegandWrappingNegAssignfor negating a number and wrapping at the boundary of the type.- wrapping_
pow WrappingPowandWrappingPowAssign, traits for raising a number to a power and wrapping at the boundary of the type.- wrapping_
square WrappingSquareandWrappingSquareAssign, traits for squaring a number and wrapping at the boundary of the type.- wrapping_
sub WrappingSubandWrappingSubAssign, traits for subtracting two numbers and wrapping at the boundary of the type.- wrapping_
sub_ mul WrappingSubMulandWrappingSubMulAssign, 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.