Module malachite_base::num::arithmetic::traits

source ·
Expand description

Various traits for performing arithmetic operations on numbers.

Traits§

  • Takes the absolute value of a number. Assumes that the number has a representable absolute number.
  • Replaces a number with its absolute value. Assumes that the number has a representable absolute number.
  • Subtracts two numbers and takes the absolute value of the difference.
  • Replaces a number with the absolute value of its difference with another number.
  • Adds a number and the product of two other numbers.
  • Adds a number and the product of two other numbers, in place.
  • Left-shifts a number (multiplies it by a power of 2), returning None if the result is not representable.
  • Right-shifts a number (divides it by a power of 2), returning None if the result is not representable.
  • Takes the ceiling of a number.
  • Replaces a number with its ceiling.
  • Divides a number by another number in place, taking the quotient and returning the remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign of the divisor (second input).
  • Divides a number by another number in place, taking the ceiling of the quotient and returning the remainder of the negative of the first number divided by the second.
  • Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign as the divisor (second input).
  • Divides a number by another number, returning the ceiling of the quotient and the remainder of the negative of the first number divided by the second.
  • Calculates the ceiling of the base-$b$ logarithm of a number.
  • Calculates the ceiling of the base-2 logarithm of a number.
  • Calculates the ceiling of the base-$2^k$ logarithm of a number.
  • Divides a number by another number, returning just the remainder. The remainder has the opposite sign as the divisor (second number).
  • Divides a number by another number, replacing the first number by the remainder. The remainder has the same sign as the divisor (second number).
  • Divides a number by $2^k$, returning just the remainder. The remainder is non-positive.
  • Divides a number by $2^k$, replacing the number by the remainder. The remainder is non-positive.
  • Finds the ceiling of the $n$th root of a number.
  • Replaces a number with the ceiling of its $n$th root.
  • Finds the ceiling of the square root of a number.
  • Replaces a number with the ceiling of its square root.
  • Takes the absolute valie of a number, returning None if the result is not representable.
  • Adds two numbers, returning None if the result is not representable.
  • Adds a number and the product of two other numbers, returning None if the result is not representable.
  • Divides two numbers, returning None if the result is not representable.
  • Computes the double factorial of a u64, returning None if the result is too large to be represented. The double factorial of a non-negative integer is the product of all the positive integers that are less than or equal to it and have the same parity as it.
  • Computes the factorial of a u64, returning None if the result is too large to be represented.
  • Calculates the LCM (least common multiple) of two numbers, returning None if the result is not representable.
  • Calculates the base-$b$ logarithm of a number, or returns None if the number is not a perfect power of $b$.
  • Calculates the base-2 logarithm of a number, or returns None if the number is not a perfect power of 2.
  • Calculates the base-$2^k$ logarithm of a number, or returns None if the number is not a perfect power of $2^k$.
  • Multiplies two numbers, returning None if the result is not representable.
  • Computes the $m$-multifactorial of a u64, returning None if the result is too large to be represented. The $m$-multifactorial of a non-negative integer $n$ is the product of all integers $k$ such that $0<k\leq n$ and $k\equiv n \pmod m$.
  • Negates a number, returning None if the result is not representable.
  • Finds the smallest integer power of 2 greater than or equal to a number, returning None if the result is not representable.
  • Raises a number to a power, returning None if the result is not representable.
  • Finds the $n$th root of a number, returning None if it is not a perfect $n$th power.
  • Finds the square root of a number, returning None if it is not a perfect square.
  • Squares a number, returning None if the result is not representable.
  • Subtracts two numbers, returning None if the result is not representable.
  • Subtracts a number by the product of two other numbers, returning None if the result is not representable.
  • Computes the subfactorial of a u64, returning None if the result is too large to be represented. The subfactorial of a non-negative integer $n$ counts the number of derangements of $n$ elements, which are the permutations in which no element is fixed.
  • Determines whether two numbers are coprime.
  • Divides a number by another number in place, returning the remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the divisor (second input).
  • Divides a number by another number in place, returning the remainder. The quotient is rounded towards zero, and the remainder has the same sign as the dividend (first input).
  • Divides two numbers, assuming the first exactly divides the second.
  • Divides a number by another number in place, assuming the first exactly divides the second.
  • Divides two numbers, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the divisor (second input).
  • Divides two numbers, returning the quotient and remainder. The quotient is rounded towards zero, and the remainder has the same sign as the dividend (first input).
  • Divides a number by another number and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.
  • Divides a number by another number in place and rounds according to a specified rounding mode. An Ordering is returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.
  • Determines whether a number is divisible by another number.
  • Determines whether a number is divisible by $2^k$.
  • Computes the double factorial of a u64. The double factorial of a non-negative integer is the product of all the positive integers that are less than or equal to it and have the same parity as it.
  • Determines whether a number is equivalent to another number modulo $m$.
  • Determines whether a number is equivalent to another number modulo $2^k$.
  • Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$.
  • Computes the factorial of a u64.
  • Takes the floor of a number.
  • Replaces a number with its floor.
  • Calculates the floor of the base-$b$ logarithm of a number.
  • Calculates the floor of the base-2 logarithm of a number.
  • Calculates the floor of the base-$2^k$ logarithm of a number.
  • Finds the floor of the $n$th root of a number.
  • Replaces a number with the floor of its $n$th root.
  • Finds the floor of the square root of a number.
  • Replaces a number with the floor of its square root.
  • Calculates the GCD (greatest common divisor) of two numbers.
  • Replaces a number with the GCD (greatest common divisor) of it and another number.
  • Determines whether a number is an integer power of 2.
  • Calculates the Jacobi symbol of two numbers.
  • Calculates the Kronecker symbol of two numbers.
  • Calculates the LCM (least common multiple) of two numbers.
  • Replaces a number with the LCM (least common multiple) of it and another number.
  • Calculates the Legendre symbol of two numbers. Typically the implementations will be identical to those of JacobiSymbol.
  • Takes the natural logarithm of a number.
  • Divides a number by another number, returning just the remainder. The remainder has the same sign as the divisor (second number).
  • Adds two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
  • Adds two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo $m$.
  • Divides a number by another number, replacing the first number by the remainder. The remainder has the same sign as the divisor (second number).
  • Finds the multiplicative inverse of a number modulo another number $m$. The input must be already reduced modulo $m$.
  • Checks whether a number is reduced modulo another number $m$.
  • Multiplies two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
  • Multiplies two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo $m$.
  • Multiplies two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
  • Multiplies two numbers modulo a third number $m$, in place.The inputs must be already reduced modulo $m$.
  • Negates a number modulo another number $m$. The input must be already reduced modulo $m$.
  • Negates a number modulo another number $m$, in place. The input must be already reduced modulo $m$.
  • Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
  • Raises a number to a power modulo another number $m$, in place. The base must be already reduced modulo $m$.
  • Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
  • Raises a number to a power modulo another number $m$, in place. The base must be already reduced modulo $m$.
  • Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.
  • Adds two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
  • Adds two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
  • Divides a number by $2^k$, replacing the number by the remainder. The remainder is non-negative.
  • Finds the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.
  • Checks whether a number is reduced modulo $2^k$.
  • Multiplies two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
  • Multiplies two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
  • Negates a number modulo $2^k$. The input must be already reduced modulo $2^k$.
  • Negates a number modulo $2^k$ in place. The input must be already reduced modulo $2^k$.
  • Raises a number to a power modulo $2^k$. The base must be already reduced modulo $2^k$.
  • Raises a number to a power modulo $2^k$, in place. The base must be already reduced modulo $2^k$.
  • Left-shifts a number (multiplies it by a power of 2) modulo $2^k$. The number must be already reduced modulo $2^k$.
  • Left-shifts a number (multiplies it by a power of 2) modulo $2^k$, in place. The number must be already reduced modulo $2^k$.
  • Right-shifts a number (divides it by a power of 2) modulo $2^k$. The number must be already reduced modulo $2^k$.
  • Right-shifts a number (divides it by a power of 2) modulo $2^k$, in place. The number must be already reduced modulo $2^k$.
  • Squares a number modulo $2^k$. The input must be already reduced modulo $2^k$.
  • Squares a number modulo $2^k$ in place. The input must be already reduced modulo $2^k$.
  • Subtracts two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
  • Subtracts two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
  • Left-shifts a number (multiplies it by a power of 2) modulo another number $m$. The number must be already reduced modulo $m$.
  • Left-shifts a number (multiplies it by a power of 2) modulo another number $m$, in place. The number must be already reduced modulo $m$.
  • Left-shifts a number (divides it by a power of 2) modulo another number $m$. The number must be already reduced modulo $m$.
  • Left-shifts a number (divides it by a power of 2) modulo another number $m$, in place. The number must be already reduced modulo $m$.
  • Squares a number modulo another number $m$. The input must be already reduced modulo $m$.
  • Squares a number modulo another number $m$, in place. The input must be already reduced modulo $m$.
  • Squares a number modulo another number $m$. The input must be already reduced modulo $m$.
  • Squares a number modulo another number $m$, in place. The input must be already reduced modulo $m$.
  • Adds two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
  • Adds two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo $m$.
  • Computes the $m$-multifactorial of a u64. The $m$-multifactorial of a non-negative integer $n$ is the product of all integers $k$ such that $0<k\leq n$ and $k\equiv n \pmod m$.
  • Replaces a number with its negative. Assumes the result is representable.
  • Divides the negative of a number by another number, returning the remainder.
  • Divides the negative of a number by another number, replacing the first number by the remainder.
  • Divides the negative of a number by $2^k$, returning the remainder.
  • Divides the negative of a number by $2^k$, replacing the number by the remainder.
  • Returns the smallest power of 2 greater than or equal to a number. Assumes the result is representable.
  • Replaces a number with the smallest power of 2 greater than or equal it. Assumes the result is representable.
  • Takes the absolute value of a number.
  • Replaces a number with its absolute value.
  • Adds two numbers.
  • Adds a number to another number in place.
  • Adds a number and the product of two other numbers.
  • Adds a number and the product of two other numbers, in place.
  • Divides two numbers.
  • Divides a number by another number in place.
  • Multiplies two numbers.
  • Multiplies a number by another number in place.
  • Negates a number.
  • Negates a number in place.
  • Raises a number to a power.
  • Raises a number to a power in place.
  • Squares a number.
  • Squares a number in place.
  • Subtracts two numbers.
  • Subtracts a number by another number in place.
  • Subtracts a number by the product of two other numbers.
  • Subtracts a number by the product of two other numbers, in place.
  • Determines whether a number is even or odd.
  • Raises a number to a power. Assumes the result is representable.
  • Raises a number to a power in place. Assumes the result is representable.
  • Raises 2 to a power.
  • Finds the reciprocal (multiplicative inverse) of a number.
  • Replaces a number with its reciprocal (multiplicative inverse).
  • Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the number.
  • Divides a number by $2^k$, replacing the number by the remainder. The remainder has the same sign as the number.
  • Replaces a number with the floor of its $n$th root, returning the remainder.
  • Finds the floor of the $n$th root of a number, returning both the root and the remainder.
  • Rotates a number left, inserting the leftmost bits into the right end.
  • Rotates a number left, inserting the leftmost bits into the right end, in place.
  • Rotates a number right, inserting the leftmost bits into the left end.
  • Rotates a number right, inserting the leftmost bits into the left end, in place.
  • Rounds a number to a multiple of another number, according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.
  • Rounds a number to a multiple of another number in place, according to a specified rounding mode. Ordering is returned, indicating whether the returned value is less than, equal to, or greater than the original value.
  • Rounds a number to a multiple of $2^k$, according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.
  • Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode. An Ordering is returned, indicating whether the returned value is less than, equal to, or greater than the original value.
  • Takes the absolute value of a number, saturating at the numeric bounds instead of overflowing.
  • Replaces a number with its absolute value, saturating at the numeric bounds instead of overflowing.
  • Adds two numbers, saturating at the numeric bounds instead of overflowing.
  • Add a number to another number in place, saturating at the numeric bounds instead of overflowing.
  • Adds a number and the product of two other numbers, saturating at the numeric bounds instead of overflowing.
  • Adds a number and the product of two other numbers in place, saturating at the numeric bounds instead of overflowing.
  • Multiplies two numbers, saturating at the numeric bounds instead of overflowing.
  • Multiplies a number by another number in place, saturating at the numeric bounds instead of overflowing.
  • Negates a number, saturating at the numeric bounds instead of overflowing.
  • Negates a number in place, saturating at the numeric bounds instead of overflowing.
  • Raises a number to a power, saturating at the numeric bounds instead of overflowing.
  • Raises a number to a power in place, saturating at the numeric bounds instead of overflowing.
  • Squares a number, saturating at the numeric bounds instead of overflowing.
  • Squares a number in place, saturating at the numeric bounds instead of overflowing.
  • Subtracts two numbers, saturating at the numeric bounds instead of overflowing.
  • Subtracts a number by another number in place, saturating at the numeric bounds instead of overflowing.
  • Subtracts a number by the product of two other numbers, saturating at the numeric bounds instead of overflowing.
  • Subtracts a number by the product of two other numbers in place, saturating at the numeric bounds instead of overflowing.
  • Left-shifts a number (multiplies it by a power of 2), rounding the result according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.
  • Left-shifts a number (multiplies it by a power of 2) in place, rounding the result according to a specified rounding mode. An Ordering is also returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.
  • Right-shifts a number (divides it by a power of 2), rounding the result according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.
  • Right-shifts a number (divides it by a power of 2) in place, rounding the result according to a specified rounding mode. An Ordering is also returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.
  • Returns Greater, Equal, or Less, depending on whether a number is positive, zero, or negative, respectively.
  • Takes the square root of a number.
  • Replaces a number with its square root.
  • Replaces a number with the floor of its square root, returning the remainder.
  • Finds the floor of the square root of a number, returning both the root and the remainder.
  • Squares a number.
  • Replaces a number with its square.
  • Subtracts a number by the product of two other numbers.
  • Subtracts a number by the product of two other numbers, in place.
  • Computes the subfactorial of a u64. The subfactorial of a non-negative integer $n$ counts the number of derangements of $n$ elements, which are the permutations in which no element is fixed.
  • Takes the absolute value of a number and converts to the unsigned equivalent.
  • Takes the absolute value of a number, wrapping around at the boundary of the type.
  • Replaces a number with its absolute value, wrapping around at the boundary of the type.
  • Adds two numbers, wrapping around at the boundary of the type.
  • Adds a number to another number in place, wrapping around at the boundary of the type.
  • Adds a number and the product of two other numbers, wrapping around at the boundary of the type.
  • Adds a number and the product of two other numbers, in place, wrapping around at the boundary of the type.
  • Divides a number by another number, wrapping around at the boundary of the type.
  • Divides a number by another number in place, wrapping around at the boundary of the type.
  • Multiplies two numbers, wrapping around at the boundary of the type.
  • Multiplies a number by another number in place, wrapping around at the boundary of the type.
  • Negates a number, wrapping around at the boundary of the type.
  • Negates a number in place, wrapping around at the boundary of the type.
  • Raises a number to a power, wrapping around at the boundary of the type.
  • Raises a number to a power in place, wrapping around at the boundary of the type.
  • Squares a number, wrapping around at the boundary of the type.
  • Squares a number in place, wrapping around at the boundary of the type.
  • Subtracts two numbers, wrapping around at the boundary of the type.
  • Subtracts a number by another number in place, wrapping around at the boundary of the type.
  • Subtracts a number by the product of two other numbers, wrapping around at the boundary of the type.
  • Subtracts a number by the product of two other numbers, in place, wrapping around at the boundary of the type.
  • Multiplies two numbers, returning the product as a pair of Self values.
  • Adds two numbers, each composed of two Self values, returning the sum as a pair of Self values.
  • Computes the quotient and remainder of two numbers. The first is composed of two Self values, and the second of a single one.
  • Subtracts two numbers, each composed of two Self values, returing the difference as a pair of Self values.
  • Adds two numbers, each composed of three Self values, returning the sum as a triple of Self values.
  • Subtracts two numbers, each composed of three Self values, returing the difference as a triple of Self values.
  • Adds two numbers, each composed of four Self values, returning the sum as a quadruple of Self values.