|
LMMS
|
#include <juce_BigInteger.h>
Private Types | |
| enum | { numPreallocatedInts = 4 } |
Private Member Functions | |
| uint32 * | getValues () const noexcept |
| uint32 * | ensureSize (size_t) |
| void | shiftLeft (int bits, int startBit) |
| void | shiftRight (int bits, int startBit) |
Private Attributes | |
| HeapBlock< uint32 > | heapAllocation |
| uint32 | preallocated [numPreallocatedInts] |
| size_t | allocatedSize |
| int | highestBit = -1 |
| bool | negative = false |
An arbitrarily large integer class.
A BigInteger can be used in a similar way to a normal integer, but has no size limit (except for memory and performance constraints).
Negative values are possible, but the value isn't stored as 2s-complement, so be careful if you use negative values and look at the values of individual bits.
@tags{Core}
| juce::BigInteger::BigInteger | ( | ) |
Creates an empty BigInteger
| juce::BigInteger::BigInteger | ( | uint32 | value | ) |
Creates a BigInteger containing an integer value in its low bits. The low 32 bits of the number are initialised with this value.
| juce::BigInteger::BigInteger | ( | int32 | value | ) |
Creates a BigInteger containing an integer value in its low bits. The low 32 bits of the number are initialised with the absolute value passed in, and its sign is set to reflect the sign of the number.
| juce::BigInteger::BigInteger | ( | int64 | value | ) |
Creates a BigInteger containing an integer value in its low bits. The low 64 bits of the number are initialised with the absolute value passed in, and its sign is set to reflect the sign of the number.
| juce::BigInteger::BigInteger | ( | const BigInteger & | other | ) |
Creates a copy of another BigInteger.
|
noexcept |
Move constructor
|
default |
Destructor.
|
noexcept |
Resets the value to 0.
|
noexcept |
Does a signed comparison of two BigIntegers.
Return values are:
|
noexcept |
Compares the magnitudes of two BigIntegers, ignoring their signs.
Return values are:
|
noexcept |
Returns the total number of set bits in the value.
| void juce::BigInteger::divideBy | ( | const BigInteger & | divisor, |
| BigInteger & | remainder ) |
Divides this value by another one and returns the remainder.
This number is divided by other, leaving the quotient in this number, with the remainder being copied to the other BigInteger passed in.
|
private |
| void juce::BigInteger::exponentModulo | ( | const BigInteger & | exponent, |
| const BigInteger & | modulus ) |
Performs a combined exponent and modulo operation. This BigInteger's value becomes (this ^ exponent) % modulus.
| void juce::BigInteger::extendedEuclidean | ( | const BigInteger & | a, |
| const BigInteger & | b, | ||
| BigInteger & | xOut, | ||
| BigInteger & | yOut ) |
Performs the Extended Euclidean algorithm. This method will set the xOut and yOut arguments such that (a * xOut) - (b * yOut) = GCD (a, b). On return, this object is left containing the value of the GCD.
| BigInteger juce::BigInteger::findGreatestCommonDivisor | ( | BigInteger | other | ) | const |
Returns the largest value that will divide both this value and the argument.
Looks for the index of the next clear bit after a given starting point.
This searches from startIndex (inclusive) upwards for the first clear bit, and returns its index.
Looks for the index of the next set bit after a given starting point.
This searches from startIndex (inclusive) upwards for the first set bit, and returns its index. If no set bits are found, it returns -1.
| BigInteger juce::BigInteger::getBitRange | ( | int | startBit, |
| int | numBits ) const |
Returns a range of bits as a new BigInteger.
e.g. getBitRangeAsInt (0, 64) would return the lowest 64 bits.
Returns a range of bits as an integer value.
e.g. getBitRangeAsInt (0, 32) would return the lowest 32 bits.
Asking for more than 32 bits isn't allowed (obviously) - for that, use getBitRange().
|
noexcept |
Returns the index of the highest set bit in the number. If the value is zero, this will return -1.
|
privatenoexcept |
Inserts a bit an a given position, shifting up any bits above it.
| void juce::BigInteger::inverseModulo | ( | const BigInteger & | modulus | ) |
Performs an inverse modulo on the value. i.e. the result is (this ^ -1) mod (modulus).
|
noexcept |
Returns true if the value is less than zero.
|
noexcept |
Returns true if the value is 1.
|
noexcept |
Returns true if no bits are set.
| void juce::BigInteger::loadFromMemoryBlock | ( | const MemoryBlock & | data | ) |
Converts a block of raw data into a number.
The data is arranged as little-endian, so the first byte of data is the low 8 bits of the number, and so on.
| void juce::BigInteger::montgomeryMultiplication | ( | const BigInteger & | other, |
| const BigInteger & | modulus, | ||
| const BigInteger & | modulusp, | ||
| int | k ) |
Performs the Montgomery Multiplication with modulo. This object is left containing the result value: ((this * other) * R1) % modulus. To get this result, we need modulus, modulusp and k such as R = 2^k, with modulus * modulusp - R * R1 = GCD(modulus, R) = 1
|
noexcept |
Inverts the sign of the number.
|
noexcept |
| BigInteger juce::BigInteger::operator% | ( | const BigInteger & | other | ) | const |
| BigInteger & juce::BigInteger::operator%= | ( | const BigInteger & | divisor | ) |
| BigInteger juce::BigInteger::operator& | ( | const BigInteger & | other | ) | const |
| BigInteger & juce::BigInteger::operator&= | ( | const BigInteger & | other | ) |
| BigInteger juce::BigInteger::operator* | ( | const BigInteger & | other | ) | const |
| BigInteger & juce::BigInteger::operator*= | ( | const BigInteger & | other | ) |
| BigInteger juce::BigInteger::operator+ | ( | const BigInteger & | other | ) | const |
| BigInteger & juce::BigInteger::operator++ | ( | ) |
| BigInteger juce::BigInteger::operator++ | ( | int | ) |
| BigInteger & juce::BigInteger::operator+= | ( | const BigInteger & | other | ) |
| BigInteger juce::BigInteger::operator- | ( | ) | const |
| BigInteger juce::BigInteger::operator- | ( | const BigInteger & | other | ) | const |
| BigInteger & juce::BigInteger::operator-- | ( | ) |
| BigInteger juce::BigInteger::operator-- | ( | int | ) |
| BigInteger & juce::BigInteger::operator-= | ( | const BigInteger & | other | ) |
| BigInteger juce::BigInteger::operator/ | ( | const BigInteger & | other | ) | const |
| BigInteger & juce::BigInteger::operator/= | ( | const BigInteger & | other | ) |
|
noexcept |
| BigInteger juce::BigInteger::operator<< | ( | int | numBitsToShift | ) | const |
| BigInteger & juce::BigInteger::operator<<= | ( | int | numBitsToShift | ) |
|
noexcept |
|
noexcept |
Move assignment operator
| BigInteger & juce::BigInteger::operator= | ( | const BigInteger & | other | ) |
Copies another BigInteger onto this one.
|
noexcept |
|
noexcept |
|
noexcept |
| BigInteger juce::BigInteger::operator>> | ( | int | numBitsToShift | ) | const |
| BigInteger & juce::BigInteger::operator>>= | ( | int | numBitsToShift | ) |
|
noexcept |
Returns the value of a specified bit in the number. If the index is out-of-range, the result will be false.
| BigInteger juce::BigInteger::operator^ | ( | const BigInteger & | other | ) | const |
| BigInteger & juce::BigInteger::operator^= | ( | const BigInteger & | other | ) |
| BigInteger juce::BigInteger::operator| | ( | const BigInteger & | other | ) | const |
| BigInteger & juce::BigInteger::operator|= | ( | const BigInteger & | other | ) |
Reads the numeric value from a string.
Specify a base such as 2 (binary), 8 (octal), 10 (decimal), 16 (hex). Any invalid characters will be ignored.
Sets a range of bits to an integer value.
Copies the given integer onto a range of bits, starting at startBit, and using up to numBits of the available bits.
|
noexcept |
Changes the sign of the number to be positive or negative.
Sets a range of bits to be either on or off.
| startBit | the first bit to change |
| numBits | the number of bits to change |
| shouldBeSet | whether to turn these bits on or off |
Shifts a section of bits left or right.
| howManyBitsLeft | how far to move the bits (+ve numbers shift it left, -ve numbers shift it right). |
| startBit | the first bit to affect - if this is > 0, only bits above that index will be affected. |
|
noexcept |
Swaps the internal contents of this with another object.
|
noexcept |
Attempts to get the lowest 64 bits of the value as an integer. If the value is bigger than the integer limits, this will return only the lower bits.
|
noexcept |
Attempts to get the lowest 32 bits of the value as an integer. If the value is bigger than the integer limits, this will return only the lower bits.
| MemoryBlock juce::BigInteger::toMemoryBlock | ( | ) | const |
Turns the number into a block of binary data.
The data is arranged as little-endian, so the first byte of data is the low 8 bits of the number, and so on.
Converts the number to a string.
Specify a base such as 2 (binary), 8 (octal), 10 (decimal), 16 (hex). If minimumNumCharacters is greater than 0, the returned string will be padded with leading zeros to reach at least that length.
|
private |
|
private |
|
private |
|
private |