Module arithmetic

Source
Expand description

Traits for arithmetic.

Modules§

abs
Abs, AbsAssign, and UnsignedAbs, traits for getting the absolute value of a number.
abs_diff
AbsDiff and AbsDiffAssign, traits for getting the absolute value of the difference between two numbers.
add_mul
AddMul and AddMulAssign, 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 and CheckedBinomialCoefficient.
ceiling
Ceiling and CeilingAssign, 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 a u64 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 and DivExactAssign, 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 and DivExactAssign, traits for dividing two numbers according to a specified RoundingMode.
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 are Factorial, DoubleFactorial, Multifactorial, Subfactorial, CheckedFactorial, CheckedDoubleFactorial, CheckedMultifactorial, and CheckedSubfactorial.
floor
Floor and FloorAssign, traits for computing the floor of a number.
gcd
Gcd and GcdAssign, 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, and KroneckerSymbol, traits for computing the Legendre, Jacobi, and Kronecker symbols of two numbers.
lcm
Lcm, LcmAssign, and CheckedLcm, 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 and ModAddAssign, 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 and ModNegAssign, 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 and ModPowerOf2AddAssign, 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 and ModPowerOf2MulAssign, traits for multiplying two numbers modulo $2^k$.
mod_power_of_2_neg
ModPowerOf2Neg and ModPowerOf2NegAssign, traits for negating a number modulo $2^k$.
mod_power_of_2_pow
ModPowerOf2Pow and ModPowerOf2PowAssign, traits for raising a number to a power modulo $2^k$.
mod_power_of_2_shl
ModPowerOf2Shl and ModPowerOf2ShlAssign, traits for left-shifting a number modulo $2^k$.
mod_power_of_2_shr
ModPowerOf2Shr and ModPowerOf2ShrAssign, traits for right-shifting a number modulo $2^k$.
mod_power_of_2_square
ModPowerOf2Square and ModPowerOf2SquareAssign, traits for squaring a number modulo $2^k$.
mod_power_of_2_sub
ModPowerOf2Sub and ModPowerOf2SubAssign, traits for subtracting one number by another modulo $2^k$.
mod_shl
ModShl and ModShlAssign, traits for left-shifting a number modulo another number.
mod_shr
ModShr and ModShrAssign, traits for right-shifting a number modulo another number.
mod_square
Traits for squaring a number modulo another number.
mod_sub
ModSub and ModSubAssign, traits for subtracting two numbers modulo another number.
neg
NegAssign, a trait for negating a number in place.
next_power_of_2
NextPowerOf2 and NextPowerOf2Assign, traits for getting the next-highest power of 2.
overflowing_abs
OverflowingAbs and OverflowingAbsAssign, traits for taking the absolute value of a number and returning a boolean indicating whether an overflow occurred.
overflowing_add
OverflowingAdd and OverflowingAddAssign, traits for adding two numbers and returning a boolean indicating whether an overflow occurred.
overflowing_add_mul
OverflowingAddMul and OverflowingAddMulAssign, traits for adding the product of two other numbers to a number and returning a boolean indicating whether an overflow occurred.
overflowing_div
OverflowingDiv and OverflowingDivAssign, traits for dividing two numbers and returning a boolean indicating whether an overflow occurred.
overflowing_mul
OverflowingMul and OverflowingMulAssign, traits for multiplying two numbers and returning a boolean indicating whether an overflow occurred.
overflowing_neg
OverflowingNeg and OverflowingNegAssign, traits for negating a number and returning a boolean indicating whether an overflow occurred.
overflowing_pow
OverflowingPow and OverflowingPowAssign, traits for raising a number to a power and returning a boolean indicating whether an overflow occurred.
overflowing_square
OverflowingSquare and OverflowingSquareAssign, traits for squaring a number and returning a boolean indicating whether an overflow occurred.
overflowing_sub
OverflowingSub and OverflowingSubAssign, traits for subtracting two numbers and returning a boolean indicating whether an overflow occurred.
overflowing_sub_mul
OverflowingSubMul and OverflowingSubMulAssign, 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 and PowAssign, 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 and CheckedPrimorial.
reciprocal
Reciprocal and ReciprocalAssign, 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, and RotateRightAssign, traits for rotating a number’s bits.
round_to_multiple
RoundToMultiple and RoundToMultipleAssign, traits for rounding a number to a multiple of another number.
round_to_multiple_of_power_of_2
RoundToMultipleOfPowerOf2 and RoundToMultipleOfPowerOf2Assign, traits for rounding a number to a multiple of a power of 2.
saturating_abs
SaturatingAbs and SaturatingAbsAssign, traits for taking the absolute value of a number and saturating at numeric bounds instead of overflowing.
saturating_add
SaturatingAdd and SaturatingAddAssign, traits for adding two numbers and saturating at numeric bounds instead of overflowing.
saturating_add_mul
SaturatingAddMul and SaturatingAddMulAssign, traits for adding the product of two numbers to a number and saturating at numeric bounds instead of overflowing.
saturating_mul
SaturatingMul and SaturatingMulAssign, traits for multiplying two numbers and saturating at numeric bounds instead of overflowing.
saturating_neg
SaturatingNeg and SaturatingNegAssign, traits for negating a number and saturating at numeric bounds instead of overflowing.
saturating_pow
SaturatingPow and SaturatingPowAssign, traits for raising a number to a power and saturating at numeric bounds instead of overflowing.
saturating_square
SaturatingSquare and SaturatingSquareAssign, traits for squaring a number and saturating at numeric bounds instead of overflowing.
saturating_sub
SaturatingSub and SaturatingSubAssign, traits for subtracting two numbers and saturating at numeric bounds instead of overflowing.
saturating_sub_mul
SaturatingSubMul and SaturatingSubMulAssign, traits for subtracting a number by the product of two numbers and saturating at numeric bounds instead of overflowing.
shl_round
ShlRound and ShlRoundAssign, traits for multiplying a number by a power of 2 and rounding according to a specified RoundingMode.
shr_round
ShrRound and ShrRoundAssign, traits for dividing a number by a power of 2 and rounding according to a specified RoundingMode.
sign
Sign, a trait for determining the sign of a number.
sqrt
Traits for taking the square root of a number.
square
Square and SquareAssign, traits for squaring a number.
sub_mul
SubMul and SubMulAssign, traits for subtracting the product of two numbers from a number.
traits
Various traits for performing arithmetic operations on numbers.
wrapping_abs
WrappingAbs and WrappingAbsAssign, traits for computing the absolute value of a number and wrapping at the boundary of the type.
wrapping_add
WrappingAdd and WrappingAddAssign, traits for adding two numbers and wrapping at the boundary of the type.
wrapping_add_mul
WrappingAddMul and WrappingAddMulAssign, traits for adding the product of two numbers to a third and wrapping at the boundary of the type.
wrapping_div
WrappingDiv and WrappingDivAssign, traits for dividing two numbers and wrapping at the boundary of the type.
wrapping_mul
WrappingMul and WrappingMulAssign, traits for multiplying two numbers and wrapping at the boundary of the type.
wrapping_neg
WrappingNeg and WrappingNegAssign for negating a number and wrapping at the boundary of the type.
wrapping_pow
WrappingPow and WrappingPowAssign, traits for raising a number to a power and wrapping at the boundary of the type.
wrapping_square
WrappingSquare and WrappingSquareAssign, traits for squaring a number and wrapping at the boundary of the type.
wrapping_sub
WrappingSub and WrappingSubAssign, traits for subtracting two numbers and wrapping at the boundary of the type.
wrapping_sub_mul
WrappingSubMul and WrappingSubMulAssign, 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.