openshot-audio  0.1.4
juce_BigInteger.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_BIGINTEGER_H_INCLUDED
30 #define JUCE_BIGINTEGER_H_INCLUDED
31 
32 
33 //==============================================================================
44 {
45 public:
46  //==============================================================================
48  BigInteger();
49 
53  BigInteger (uint32 value);
54 
59  BigInteger (int32 value);
60 
65  BigInteger (int64 value);
66 
68  BigInteger (const BigInteger&);
69 
70  #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
72  BigInteger& operator= (BigInteger&&) noexcept;
73  #endif
74 
76  ~BigInteger();
77 
78  //==============================================================================
80  BigInteger& operator= (const BigInteger&);
81 
83  void swapWith (BigInteger&) noexcept;
84 
85  //==============================================================================
89  bool operator[] (int bit) const noexcept;
90 
92  bool isZero() const noexcept;
93 
95  bool isOne() const noexcept;
96 
100  int toInteger() const noexcept;
101 
105  int64 toInt64() const noexcept;
106 
107  //==============================================================================
109  void clear();
110 
112  void clearBit (int bitNumber) noexcept;
113 
115  void setBit (int bitNumber);
116 
118  void setBit (int bitNumber, bool shouldBeSet);
119 
126  void setRange (int startBit, int numBits, bool shouldBeSet);
127 
129  void insertBit (int bitNumber, bool shouldBeSet);
130 
136  BigInteger getBitRange (int startBit, int numBits) const;
137 
145  uint32 getBitRangeAsInt (int startBit, int numBits) const noexcept;
146 
152  void setBitRangeAsInt (int startBit, int numBits, uint32 valueToSet);
153 
159  void shiftBits (int howManyBitsLeft, int startBit);
160 
162  int countNumberOfSetBits() const noexcept;
163 
169  int findNextSetBit (int startIndex) const noexcept;
170 
176  int findNextClearBit (int startIndex) const noexcept;
177 
181  int getHighestBit() const noexcept;
182 
183  //==============================================================================
184  // All the standard arithmetic ops...
185 
186  BigInteger& operator+= (const BigInteger&);
187  BigInteger& operator-= (const BigInteger&);
188  BigInteger& operator*= (const BigInteger&);
189  BigInteger& operator/= (const BigInteger&);
190  BigInteger& operator|= (const BigInteger&);
191  BigInteger& operator&= (const BigInteger&);
192  BigInteger& operator^= (const BigInteger&);
193  BigInteger& operator%= (const BigInteger&);
194  BigInteger& operator<<= (int numBitsToShift);
195  BigInteger& operator>>= (int numBitsToShift);
196  BigInteger& operator++();
197  BigInteger& operator--();
198  BigInteger operator++ (int);
199  BigInteger operator-- (int);
200 
201  BigInteger operator-() const;
202  BigInteger operator+ (const BigInteger&) const;
203  BigInteger operator- (const BigInteger&) const;
204  BigInteger operator* (const BigInteger&) const;
205  BigInteger operator/ (const BigInteger&) const;
206  BigInteger operator| (const BigInteger&) const;
207  BigInteger operator& (const BigInteger&) const;
208  BigInteger operator^ (const BigInteger&) const;
209  BigInteger operator% (const BigInteger&) const;
210  BigInteger operator<< (int numBitsToShift) const;
211  BigInteger operator>> (int numBitsToShift) const;
212 
213  bool operator== (const BigInteger&) const noexcept;
214  bool operator!= (const BigInteger&) const noexcept;
215  bool operator< (const BigInteger&) const noexcept;
216  bool operator<= (const BigInteger&) const noexcept;
217  bool operator> (const BigInteger&) const noexcept;
218  bool operator>= (const BigInteger&) const noexcept;
219 
220  //==============================================================================
228  int compare (const BigInteger& other) const noexcept;
229 
237  int compareAbsolute (const BigInteger& other) const noexcept;
238 
244  void divideBy (const BigInteger& divisor, BigInteger& remainder);
245 
247  BigInteger findGreatestCommonDivisor (BigInteger other) const;
248 
252  void exponentModulo (const BigInteger& exponent, const BigInteger& modulus);
253 
257  void inverseModulo (const BigInteger& modulus);
258 
259  //==============================================================================
263  bool isNegative() const noexcept;
264 
268  void setNegative (bool shouldBeNegative) noexcept;
269 
273  void negate() noexcept;
274 
275  //==============================================================================
282  String toString (int base, int minimumNumCharacters = 1) const;
283 
289  void parseString (StringRef text, int base);
290 
291  //==============================================================================
299  MemoryBlock toMemoryBlock() const;
300 
308  void loadFromMemoryBlock (const MemoryBlock& data);
309 
310 private:
311  //==============================================================================
312  HeapBlock<uint32> values;
313  size_t numValues;
314  int highestBit;
315  bool negative;
316 
317  void ensureSize (size_t);
318  void shiftLeft (int bits, int startBit);
319  void shiftRight (int bits, int startBit);
320 
322 };
323 
326 
327 //==============================================================================
328 #ifndef DOXYGEN
329  // For backwards compatibility, BitArray is defined as an alias for BigInteger.
331 #endif
332 
333 
334 #endif // JUCE_BIGINTEGER_H_INCLUDED
Definition: juce_BigInteger.h:43
#define noexcept
Definition: juce_CompilerSupport.h:141
JUCE_API bool JUCE_CALLTYPE operator>(const String &s1, const String &s2) noexcept
Definition: juce_core.cpp:589
Definition: juce_MemoryBlock.h:38
#define JUCE_CALLTYPE
Definition: juce_PlatformDefs.h:50
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
unsigned int uint32
Definition: juce_MathsFunctions.h:51
Definition: juce_OutputStream.h:42
long long int64
Definition: juce_MathsFunctions.h:60
OutputStream &JUCE_CALLTYPE operator<<(OutputStream &stream, const BigInteger &value)
Definition: juce_BigInteger.cpp:896
JUCE_API bool JUCE_CALLTYPE operator<(const String &s1, const String &s2) noexcept
Definition: juce_core.cpp:590
bool operator==(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:565
BigInteger BitArray
Definition: juce_BigInteger.h:330
JUCE_API bool JUCE_CALLTYPE operator<=(const String &s1, const String &s2) noexcept
Definition: juce_core.cpp:592
JUCE_API bool JUCE_CALLTYPE operator>=(const String &s1, const String &s2) noexcept
Definition: juce_core.cpp:591
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition: juce_LeakedObjectDetector.h:141
bool operator!=(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:566
signed int int32
Definition: juce_MathsFunctions.h:49
Definition: juce_StringRef.h:65