OpenShot Audio Library | OpenShotAudio: juce_BigInteger.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0 |

Loading...
Searching...
No Matches
juce_BigInteger.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
38 class JUCE_API BigInteger
39{
40public:
41 //==============================================================================
43 BigInteger();
44
48 BigInteger (uint32 value);
49
54 BigInteger (int32 value);
55
60 BigInteger (int64 value);
61
63 BigInteger (const BigInteger&);
64
66 BigInteger (BigInteger&&) noexcept;
67
69 BigInteger& operator= (BigInteger&&) noexcept;
70
72 ~BigInteger();
73
74 //==============================================================================
76 BigInteger& operator= (const BigInteger&);
77
79 void swapWith (BigInteger&) noexcept;
80
81 //==============================================================================
85 bool operator[] (int bit) const noexcept;
86
88 bool isZero() const noexcept;
89
91 bool isOne() const noexcept;
92
96 int toInteger() const noexcept;
97
101 int64 toInt64() const noexcept;
102
103 //==============================================================================
105 BigInteger& clear() noexcept;
106
108 BigInteger& clearBit (int bitNumber) noexcept;
109
111 BigInteger& setBit (int bitNumber);
112
114 BigInteger& setBit (int bitNumber, bool shouldBeSet);
115
122 BigInteger& setRange (int startBit, int numBits, bool shouldBeSet);
123
125 BigInteger& insertBit (int bitNumber, bool shouldBeSet);
126
132 BigInteger getBitRange (int startBit, int numBits) const;
133
141 uint32 getBitRangeAsInt (int startBit, int numBits) const noexcept;
142
148 BigInteger& setBitRangeAsInt (int startBit, int numBits, uint32 valueToSet);
149
155 BigInteger& shiftBits (int howManyBitsLeft, int startBit);
156
158 int countNumberOfSetBits() const noexcept;
159
165 int findNextSetBit (int startIndex) const noexcept;
166
172 int findNextClearBit (int startIndex) const noexcept;
173
177 int getHighestBit() const noexcept;
178
179 //==============================================================================
183 bool isNegative() const noexcept;
184
188 void setNegative (bool shouldBeNegative) noexcept;
189
193 void negate() noexcept;
194
195 //==============================================================================
196 // All the standard arithmetic ops...
197
198 BigInteger& operator+= (const BigInteger&);
199 BigInteger& operator-= (const BigInteger&);
200 BigInteger& operator*= (const BigInteger&);
201 BigInteger& operator/= (const BigInteger&);
202 BigInteger& operator|= (const BigInteger&);
203 BigInteger& operator&= (const BigInteger&);
204 BigInteger& operator^= (const BigInteger&);
205 BigInteger& operator%= (const BigInteger&);
206 BigInteger& operator<<= (int numBitsToShift);
207 BigInteger& operator>>= (int numBitsToShift);
208 BigInteger& operator++();
209 BigInteger& operator--();
210 BigInteger operator++ (int);
211 BigInteger operator-- (int);
212
213 BigInteger operator-() const;
214 BigInteger operator+ (const BigInteger&) const;
215 BigInteger operator- (const BigInteger&) const;
216 BigInteger operator* (const BigInteger&) const;
217 BigInteger operator/ (const BigInteger&) const;
218 BigInteger operator| (const BigInteger&) const;
219 BigInteger operator& (const BigInteger&) const;
220 BigInteger operator^ (const BigInteger&) const;
221 BigInteger operator% (const BigInteger&) const;
222 BigInteger operator<< (int numBitsToShift) const;
223 BigInteger operator>> (int numBitsToShift) const;
224
225 bool operator== (const BigInteger&) const noexcept;
226 bool operator!= (const BigInteger&) const noexcept;
227 bool operator< (const BigInteger&) const noexcept;
228 bool operator<= (const BigInteger&) const noexcept;
229 bool operator> (const BigInteger&) const noexcept;
230 bool operator>= (const BigInteger&) const noexcept;
231
232 //==============================================================================
240 int compare (const BigInteger& other) const noexcept;
241
249 int compareAbsolute (const BigInteger& other) const noexcept;
250
251 //==============================================================================
257 void divideBy (const BigInteger& divisor, BigInteger& remainder);
258
260 BigInteger findGreatestCommonDivisor (BigInteger other) const;
261
265 void exponentModulo (const BigInteger& exponent, const BigInteger& modulus);
266
270 void inverseModulo (const BigInteger& modulus);
271
277 void montgomeryMultiplication (const BigInteger& other, const BigInteger& modulus,
278 const BigInteger& modulusp, int k);
279
284 void extendedEuclidean (const BigInteger& a, const BigInteger& b,
285 BigInteger& xOut, BigInteger& yOut);
286
287 //==============================================================================
294 String toString (int base, int minimumNumCharacters = 1) const;
295
301 void parseString (StringRef text, int base);
302
303 //==============================================================================
311 MemoryBlock toMemoryBlock() const;
312
320 void loadFromMemoryBlock (const MemoryBlock& data);
321
322private:
323 //==============================================================================
324 enum { numPreallocatedInts = 4 };
325 HeapBlock<uint32> heapAllocation;
326 uint32 preallocated[numPreallocatedInts];
327 size_t allocatedSize;
328 int highestBit = -1;
329 bool negative = false;
330
331 uint32* getValues() const noexcept;
332 uint32* ensureSize (size_t);
333 void shiftLeft (int bits, int startBit);
334 void shiftRight (int bits, int startBit);
335
336 JUCE_LEAK_DETECTOR (BigInteger)
337};
338
340 OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value);
341
342} // namespace juce
juce::BigInteger
Definition juce_BigInteger.h:39
juce::BigInteger::clear
BigInteger & clear() noexcept
Definition juce_BigInteger.cpp:281
juce::BigInteger::toMemoryBlock
MemoryBlock toMemoryBlock() const
Definition juce_BigInteger.cpp:1193
juce::BigInteger::isOne
bool isOne() const noexcept
Definition juce_BigInteger.cpp:356
juce::BigInteger::getBitRange
BigInteger getBitRange(int startBit, int numBits) const
Definition juce_BigInteger.cpp:219
juce::BigInteger::parseString
void parseString(StringRef text, int base)
Definition juce_BigInteger.cpp:1145
juce::BigInteger::toInt64
int64 toInt64() const noexcept
Definition juce_BigInteger.cpp:212
juce::BigInteger::exponentModulo
void exponentModulo(const BigInteger &exponent, const BigInteger &modulus)
Definition juce_BigInteger.cpp:919
juce::BigInteger::setNegative
void setNegative(bool shouldBeNegative) noexcept
Definition juce_BigInteger.cpp:366
juce::BigInteger::~BigInteger
~BigInteger()
juce::BigInteger::getBitRangeAsInt
uint32 getBitRangeAsInt(int startBit, int numBits) const noexcept
Definition juce_BigInteger.cpp:237
juce::BigInteger::setRange
BigInteger & setRange(int startBit, int numBits, bool shouldBeSet)
Definition juce_BigInteger.cpp:333
juce::BigInteger::findGreatestCommonDivisor
BigInteger findGreatestCommonDivisor(BigInteger other) const
Definition juce_BigInteger.cpp:900
juce::BigInteger::extendedEuclidean
void extendedEuclidean(const BigInteger &a, const BigInteger &b, BigInteger &xOut, BigInteger &yOut)
Definition juce_BigInteger.cpp:1005
juce::BigInteger::getHighestBit
int getHighestBit() const noexcept
Definition juce_BigInteger.cpp:391
juce::BigInteger::divideBy
void divideBy(const BigInteger &divisor, BigInteger &remainder)
Definition juce_BigInteger.cpp:578
juce::BigInteger::toString
String toString(int base, int minimumNumCharacters=1) const
Definition juce_BigInteger.cpp:1098
juce::BigInteger::shiftBits
BigInteger & shiftBits(int howManyBitsLeft, int startBit)
Definition juce_BigInteger.cpp:873
juce::BigInteger::findNextClearBit
int findNextClearBit(int startIndex) const noexcept
Definition juce_BigInteger.cpp:413
juce::BigInteger::compare
int compare(const BigInteger &other) const noexcept
Definition juce_BigInteger.cpp:743
juce::BigInteger::insertBit
BigInteger & insertBit(int bitNumber, bool shouldBeSet)
Definition juce_BigInteger.cpp:341
juce::BigInteger::setBitRangeAsInt
BigInteger & setBitRangeAsInt(int startBit, int numBits, uint32 valueToSet)
Definition juce_BigInteger.cpp:263
juce::BigInteger::clearBit
BigInteger & clearBit(int bitNumber) noexcept
Definition juce_BigInteger.cpp:320
juce::BigInteger::BigInteger
BigInteger()
Definition juce_BigInteger.cpp:54
juce::BigInteger::negate
void negate() noexcept
Definition juce_BigInteger.cpp:371
juce::BigInteger::findNextSetBit
int findNextSetBit(int startIndex) const noexcept
Definition juce_BigInteger.cpp:402
juce::BigInteger::loadFromMemoryBlock
void loadFromMemoryBlock(const MemoryBlock &data)
Definition juce_BigInteger.cpp:1205
juce::BigInteger::isZero
bool isZero() const noexcept
Definition juce_BigInteger.cpp:351
juce::BigInteger::countNumberOfSetBits
int countNumberOfSetBits() const noexcept
Definition juce_BigInteger.cpp:380
juce::BigInteger::swapWith
void swapWith(BigInteger &) noexcept
Definition juce_BigInteger.cpp:133
juce::BigInteger::montgomeryMultiplication
void montgomeryMultiplication(const BigInteger &other, const BigInteger &modulus, const BigInteger &modulusp, int k)
Definition juce_BigInteger.cpp:985
juce::BigInteger::isNegative
bool isNegative() const noexcept
Definition juce_BigInteger.cpp:361
juce::BigInteger::compareAbsolute
int compareAbsolute(const BigInteger &other) const noexcept
Definition juce_BigInteger.cpp:756
juce::BigInteger::setBit
BigInteger & setBit(int bitNumber)
Definition juce_BigInteger.cpp:294
juce::BigInteger::toInteger
int toInteger() const noexcept
Definition juce_BigInteger.cpp:206
juce::BigInteger::inverseModulo
void inverseModulo(const BigInteger &modulus)
Definition juce_BigInteger.cpp:1042
juce::HeapBlock
Definition juce_HeapBlock.h:87
juce::MemoryBlock
Definition juce_MemoryBlock.h:33
juce::OutputStream
Definition juce_OutputStream.h:38
juce::StringRef
Definition juce_StringRef.h:62
juce::String
Definition juce_String.h:53