Module malachite_base::num::arithmetic
source · Expand description
Traits for arithmetic.
Modules§
AbsDiffandAbsDiffAssign, traits for getting the absolute value of the difference between two numbers.AddMulandAddMulAssign, 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
Nonein that case:BinomialCoefficientandCheckedBinomialCoefficient. CeilingandCeilingAssign, 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 au64and 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.DivExactandDivExactAssign, 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
Nonein that case. The traits areFactorial,DoubleFactorial,Multifactorial,Subfactorial,CheckedFactorial,CheckedDoubleFactorial,CheckedMultifactorial, andCheckedSubfactorial. FloorandFloorAssign, 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.
ModAddandModAddAssign, 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.
ModNegandModNegAssign, 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.
ModPowerOf2AddandModPowerOf2AddAssign, 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$.ModPowerOf2MulandModPowerOf2MulAssign, traits for multiplying two numbers modulo $2^k$.ModPowerOf2NegandModPowerOf2NegAssign, traits for negating a number modulo $2^k$.ModPowerOf2PowandModPowerOf2PowAssign, traits for raising a number to a power modulo $2^k$.ModPowerOf2ShlandModPowerOf2ShlAssign, traits for left-shifting a number modulo $2^k$.ModPowerOf2ShrandModPowerOf2ShrAssign, traits for right-shifting a number modulo $2^k$.ModPowerOf2SquareandModPowerOf2SquareAssign, traits for squaring a number modulo $2^k$.ModPowerOf2SubandModPowerOf2SubAssign, traits for subtracting one number by another modulo $2^k$.ModShlandModShlAssign, traits for left-shifting a number modulo another number.ModShrandModShrAssign, traits for right-shifting a number modulo another number.- Traits for squaring a number modulo another number.
ModSubandModSubAssign, traits for subtracting two numbers modulo another number.NegAssign, a trait for negating a number in place.NextPowerOf2andNextPowerOf2Assign, traits for getting the next-highest power of 2.OverflowingAbsandOverflowingAbsAssign, traits for taking the absolute value of a number and returning a boolean indicating whether an overflow occurred.OverflowingAddandOverflowingAddAssign, traits for adding two numbers and returning a boolean indicating whether an overflow occurred.OverflowingAddMulandOverflowingAddMulAssign, traits for adding the product of two other numbers to a number and returning a boolean indicating whether an overflow occurred.OverflowingDivandOverflowingDivAssign, traits for dividing two numbers and returning a boolean indicating whether an overflow occurred.OverflowingMulandOverflowingMulAssign, traits for multiplying two numbers and returning a boolean indicating whether an overflow occurred.OverflowingNegandOverflowingNegAssign, traits for negating a number and returning a boolean indicating whether an overflow occurred.OverflowingPowandOverflowingPowAssign, traits for raising a number to a power and returning a boolean indicating whether an overflow occurred.OverflowingSquareandOverflowingSquareAssign, traits for squaring a number and returning a boolean indicating whether an overflow occurred.OverflowingSubandOverflowingSubAssign, traits for subtracting two numbers and returning a boolean indicating whether an overflow occurred.OverflowingSubMulandOverflowingSubMulAssign, 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
Nonein that case:PrimorialandCheckedPrimorial. - Traits for taking the $n$th root of a number.
RotateLeft,RotateLeftAssign,RotateRight, andRotateRightAssign, traits for rotating a number’s bits.RoundToMultipleandRoundToMultipleAssign, traits for rounding a number to a multiple of another number.RoundToMultipleOfPowerOf2andRoundToMultipleOfPowerOf2Assign, traits for rounding a number to a multiple of a power of 2.SaturatingAbsandSaturatingAbsAssign, traits for taking the absolute value of a number and saturating at numeric bounds instead of overflowing.SaturatingAddandSaturatingAddAssign, traits for adding two numbers and saturating at numeric bounds instead of overflowing.SaturatingAddMulandSaturatingAddMulAssign, traits for adding the product of two numbers to a number and saturating at numeric bounds instead of overflowing.SaturatingMulandSaturatingMulAssign, traits for multiplying two numbers and saturating at numeric bounds instead of overflowing.SaturatingNegandSaturatingNegAssign, traits for negating a number and saturating at numeric bounds instead of overflowing.SaturatingPowandSaturatingPowAssign, traits for raising a number to a power and saturating at numeric bounds instead of overflowing.SaturatingSquareandSaturatingSquareAssign, traits for squaring a number and saturating at numeric bounds instead of overflowing.SaturatingSubandSaturatingSubAssign, traits for subtracting two numbers and saturating at numeric bounds instead of overflowing.SaturatingSubMulandSaturatingSubMulAssign, traits for subtracting a number by the product of two numbers and saturating at numeric bounds instead of overflowing.ShlRoundandShlRoundAssign, traits for multiplying a number by a power of 2 and rounding according to a specifiedRoundingMode.ShrRoundandShrRoundAssign, 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.
SquareandSquareAssign, traits for squaring a number.SubMulandSubMulAssign, traits for subtracting the product of two numbers from a number.- Various traits for performing arithmetic operations on numbers.
WrappingAbsandWrappingAbsAssign, traits for computing the absolute value of a number and wrapping at the boundary of the type.WrappingAddandWrappingAddAssign, traits for adding two numbers and wrapping at the boundary of the type.WrappingAddMulandWrappingAddMulAssign, traits for adding the product of two numbers to a third and wrapping at the boundary of the type.WrappingDivandWrappingDivAssign, traits for dividing two numbers and wrapping at the boundary of the type.WrappingMulandWrappingMulAssign, traits for multiplying two numbers and wrapping at the boundary of the type.WrappingNegandWrappingNegAssignfor negating a number and wrapping at the boundary of the type.WrappingPowandWrappingPowAssign, traits for raising a number to a power and wrapping at the boundary of the type.WrappingSquareandWrappingSquareAssign, traits for squaring a number and wrapping at the boundary of the type.WrappingSubandWrappingSubAssign, traits for subtracting two numbers and wrapping at the boundary of the type.WrappingSubMulandWrappingSubMulAssign, 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.