Module malachite_base::num::arithmetic
source · Expand description
Traits for arithmetic.
Modules§
AbsDiff
andAbsDiffAssign
, traits for getting the absolute value of the difference between two numbers.AddMul
andAddMulAssign
, traits for adding a number and the product of two other numbers.ArithmeticCheckedShl
, a trait for left-shifting a number and checking whether the result is representable.ArithmeticCheckedShr
, a trait for right-shifting a number and checking whether the result is representable.- 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
andCeilingAssign
, traits for computing the ceiling of a number.CheckedAbs
, a trait for computing the absolute value of number and checking whether the result is representable.CheckedAdd
, a trait for adding two numbers and checking whether the result is representable.CheckedAddMul
, a trait for adding a number and the product of two other numbers, and checking whether the result is representable.CheckedDiv
, a trait for dividing two numbers and checking whether the result is representable.CheckedMul
, a trait for multiplying two numbers and checking whether the result is representable.CheckedNeg
, a trait for negating a number and checking whether the result is representable.CheckedNextPowerOf2
, a trait for getting the next-highest power of 2, if it’s representable.CheckedPow
, a trait for raising a number to the power of au64
and checking whether the result is representable.CheckedSquare
, a trait for squaring a number and checking whether the result is representable.CheckedSub
, a trait for subtracting two numbers and checking whether the result is representable.CheckedSubMul
, a trait for subtracting the product of two numbers from another number, and checking whether the result is representable.CoprimeWith
, a trait for determining whether two numbers are coprime.DivExact
andDivExactAssign
, traits for dividing two numbers when it’s known that the division is exact.- Traits for simultaneously finding the quotient and remainder of two numbers, subject to various rounding rules.
DivisibleBy
, a trait for determining whether one number is divisible by another.DivisibleByPowerOf2
, a trait for determining whether a number is divisible by $2^k$.EqMod
, a trait for determining whether one number is equal by another modulo a third.EqModPowerOf2
, a trait for determining whether one number is equal to another modulo $2^k$.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)$.- 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
andFloorAssign
, traits for computing the floor of a number.IsPowerOf2
, a trait for determining whether a number is an integer power of 2.LegendreSymbol
,JacobiSymbol
, andKroneckerSymbol
, traits for computing the Legendre, Jacobi, and Kronecker symbols of two numbers.Lcm
,LcmAssign
, andCheckedLcm
, traits for computing the LCM (least common multiple) of two numbers.- Traits for taking the base-$b$ logarithm of a number.
- Traits for taking the base-2 logarithm of a number.
- Traits for taking the base-$2^k$ logarithm of a number.
ModAdd
andModAddAssign
, traits for adding two numbers modulo another number.ModInverse
, a trait for finding the multiplicative inverse of a number modulo another number.ModIsReduced
, a trait for checking whether a number is reduced modulo another number.- Traits for multiplying two numbers modulo another number.
ModNeg
andModNegAssign
, traits for negating a number modulo another number.- Traits for finding the remainder of two numbers, subject to various rounding rules.
- Traits for raising a number to a power modulo another number.
- Traits for finding the remainder of a number divided by $2^k$, subject to various rounding rules.
ModPowerOf2Add
andModPowerOf2AddAssign
, traits for adding two numbers modulo $2^k$.ModPowerOf2Inverse
, a trait for finding the multiplicative inverse of a number modulo $2^k$.ModPowerOf2IsReduced
, a trait for checking whether a number is reduced modulo $2^k$.ModPowerOf2Mul
andModPowerOf2MulAssign
, traits for multiplying two numbers modulo $2^k$.ModPowerOf2Neg
andModPowerOf2NegAssign
, traits for negating a number modulo $2^k$.ModPowerOf2Pow
andModPowerOf2PowAssign
, traits for raising a number to a power modulo $2^k$.ModPowerOf2Shl
andModPowerOf2ShlAssign
, traits for left-shifting a number modulo $2^k$.ModPowerOf2Shr
andModPowerOf2ShrAssign
, traits for right-shifting a number modulo $2^k$.ModPowerOf2Square
andModPowerOf2SquareAssign
, traits for squaring a number modulo $2^k$.ModPowerOf2Sub
andModPowerOf2SubAssign
, traits for subtracting one number by another modulo $2^k$.ModShl
andModShlAssign
, traits for left-shifting a number modulo another number.ModShr
andModShrAssign
, traits for right-shifting a number modulo another number.- Traits for squaring a number modulo another number.
ModSub
andModSubAssign
, traits for subtracting two numbers modulo another number.NegAssign
, a trait for negating a number in place.NextPowerOf2
andNextPowerOf2Assign
, traits for getting the next-highest power of 2.OverflowingAbs
andOverflowingAbsAssign
, traits for taking the absolute value of a number and returning a boolean indicating whether an overflow occurred.OverflowingAdd
andOverflowingAddAssign
, traits for adding two numbers and returning a boolean indicating whether an overflow occurred.OverflowingAddMul
andOverflowingAddMulAssign
, traits for adding the product of two other numbers to a number and returning a boolean indicating whether an overflow occurred.OverflowingDiv
andOverflowingDivAssign
, traits for dividing two numbers and returning a boolean indicating whether an overflow occurred.OverflowingMul
andOverflowingMulAssign
, traits for multiplying two numbers and returning a boolean indicating whether an overflow occurred.OverflowingNeg
andOverflowingNegAssign
, traits for negating a number and returning a boolean indicating whether an overflow occurred.OverflowingPow
andOverflowingPowAssign
, traits for raising a number to a power and returning a boolean indicating whether an overflow occurred.OverflowingSquare
andOverflowingSquareAssign
, traits for squaring a number and returning a boolean indicating whether an overflow occurred.OverflowingSub
andOverflowingSubAssign
, traits for subtracting two numbers and returning a boolean indicating whether an overflow occurred.OverflowingSubMul
andOverflowingSubMulAssign
, traits for subtracting the product of two other numbers from a number and returning a boolean indicating whether an overflow occurred.Parity
, a trait for determining whether a number is even or odd.PowerOf2
, a trait for computing a power of 2.- 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
andReciprocalAssign
, traits for computing the reciprocal (multiplicative inverse) of a number.- Traits for taking the $n$th root of a number.
RotateLeft
,RotateLeftAssign
,RotateRight
, andRotateRightAssign
, traits for rotating a number’s bits.RoundToMultiple
andRoundToMultipleAssign
, traits for rounding a number to a multiple of another number.RoundToMultipleOfPowerOf2
andRoundToMultipleOfPowerOf2Assign
, traits for rounding a number to a multiple of a power of 2.SaturatingAbs
andSaturatingAbsAssign
, traits for taking the absolute value of a number and saturating at numeric bounds instead of overflowing.SaturatingAdd
andSaturatingAddAssign
, traits for adding two numbers and saturating at numeric bounds instead of overflowing.SaturatingAddMul
andSaturatingAddMulAssign
, traits for adding the product of two numbers to a number and saturating at numeric bounds instead of overflowing.SaturatingMul
andSaturatingMulAssign
, traits for multiplying two numbers and saturating at numeric bounds instead of overflowing.SaturatingNeg
andSaturatingNegAssign
, traits for negating a number and saturating at numeric bounds instead of overflowing.SaturatingPow
andSaturatingPowAssign
, traits for raising a number to a power and saturating at numeric bounds instead of overflowing.SaturatingSquare
andSaturatingSquareAssign
, traits for squaring a number and saturating at numeric bounds instead of overflowing.SaturatingSub
andSaturatingSubAssign
, traits for subtracting two numbers and saturating at numeric bounds instead of overflowing.SaturatingSubMul
andSaturatingSubMulAssign
, traits for subtracting a number by the product of two numbers and saturating at numeric bounds instead of overflowing.ShlRound
andShlRoundAssign
, traits for multiplying a number by a power of 2 and rounding according to a specifiedRoundingMode
.ShrRound
andShrRoundAssign
, traits for dividing a number by a power of 2 and rounding according to a specifiedRoundingMode
.Sign
, a trait for determining the sign of a number.- Traits for taking the square root of a number.
Square
andSquareAssign
, traits for squaring a number.SubMul
andSubMulAssign
, traits for subtracting the product of two numbers from a number.- Various traits for performing arithmetic operations on numbers.
WrappingAbs
andWrappingAbsAssign
, traits for computing the absolute value of a number and wrapping at the boundary of the type.WrappingAdd
andWrappingAddAssign
, traits for adding two numbers and wrapping at the boundary of the type.WrappingAddMul
andWrappingAddMulAssign
, traits for adding the product of two numbers to a third and wrapping at the boundary of the type.WrappingDiv
andWrappingDivAssign
, traits for dividing two numbers and wrapping at the boundary of the type.WrappingMul
andWrappingMulAssign
, traits for multiplying two numbers and wrapping at the boundary of the type.WrappingNeg
andWrappingNegAssign
for negating a number and wrapping at the boundary of the type.WrappingPow
andWrappingPowAssign
, traits for raising a number to a power and wrapping at the boundary of the type.WrappingSquare
andWrappingSquareAssign
, traits for squaring a number and wrapping at the boundary of the type.WrappingSub
andWrappingSubAssign
, traits for subtracting two numbers and wrapping at the boundary of the type.WrappingSubMul
andWrappingSubMulAssign
, traits for subtracting a number by the product of two other numbers and wrapping at the boundary of the type.XMulYToZZ
, a trait for multiplying two numbers and returning the result as a double-width number.XXAddYYToZZ
, a trait for adding two double-width numbers and returning the result as a double-width number.XXDivModYToQR
, a trait for dividing a double-width number by a single-width number and returning the quotient and remainder.XXSubYYToZZ
, a trait for subtracting two double-width numbers and returning the result as a double-width number.XXXAddYYYToZZZ
, a trait for adding two triple-width numbers and returning the result as a triple-width number.XXXSubYYYToZZZ
, a trait for subtracting two triple-width numbers and returning the result as a triple-width number.XXXXAddYYYYToZZZZ
, a trait for adding two quadruple-width numbers and returning the result as a quadruple-width number.