LMMS
Loading...
Searching...
No Matches
juce_BigInteger.h
Go to the documentation of this file.
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//==============================================================================
39{
40public:
41 //==============================================================================
43 BigInteger();
44
49
55
61
63 BigInteger (const BigInteger&);
64
66 BigInteger (BigInteger&&) noexcept;
67
69 BigInteger& operator= (BigInteger&&) noexcept;
70
72 ~BigInteger() = default;
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
97
102
103 //==============================================================================
105 void clear() noexcept;
106
108 void clearBit (int bitNumber) noexcept;
109
111 void setBit (int bitNumber);
112
114 void setBit (int bitNumber, bool shouldBeSet);
115
122 void setRange (int startBit, int numBits, bool shouldBeSet);
123
125 void 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 void setBitRangeAsInt (int startBit, int numBits, uint32 valueToSet);
149
155 void shiftBits (int howManyBitsLeft, int startBit);
156
159
165 int findNextSetBit (int startIndex) const noexcept;
166
172 int findNextClearBit (int startIndex) const noexcept;
173
178
179 //==============================================================================
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 //==============================================================================
241
250
251 //==============================================================================
257 void divideBy (const BigInteger& divisor, BigInteger& remainder);
258
261
265 void exponentModulo (const BigInteger& exponent, const BigInteger& modulus);
266
270 void inverseModulo (const BigInteger& modulus);
271
278 const BigInteger& modulusp, int k);
279
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 //==============================================================================
312
321
322private:
323 //==============================================================================
328 int highestBit = -1;
329 bool negative = false;
330
332 uint32* ensureSize (size_t);
333 void shiftLeft (int bits, int startBit);
334 void shiftRight (int bits, int startBit);
335
337};
338
341
342} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
uint8_t a
Definition Spc_Cpu.h:141
MemoryBlock toMemoryBlock() const
Definition juce_BigInteger.cpp:1176
@ numPreallocatedInts
Definition juce_BigInteger.h:324
void shiftLeft(int bits, int startBit)
Definition juce_BigInteger.cpp:767
bool isOne() const noexcept
Definition juce_BigInteger.cpp:341
void clearBit(int bitNumber) noexcept
Definition juce_BigInteger.cpp:310
BigInteger getBitRange(int startBit, int numBits) const
Definition juce_BigInteger.cpp:217
void parseString(StringRef text, int base)
Definition juce_BigInteger.cpp:1128
uint32 preallocated[numPreallocatedInts]
Definition juce_BigInteger.h:326
int64 toInt64() const noexcept
Definition juce_BigInteger.cpp:210
~BigInteger()=default
void exponentModulo(const BigInteger &exponent, const BigInteger &modulus)
Definition juce_BigInteger.cpp:902
void setNegative(bool shouldBeNegative) noexcept
Definition juce_BigInteger.cpp:351
uint32 getBitRangeAsInt(int startBit, int numBits) const noexcept
Definition juce_BigInteger.cpp:235
bool negative
Definition juce_BigInteger.h:329
void clear() noexcept
Definition juce_BigInteger.cpp:277
BigInteger findGreatestCommonDivisor(BigInteger other) const
Definition juce_BigInteger.cpp:883
uint32 * getValues() const noexcept
Definition juce_BigInteger.cpp:165
HeapBlock< uint32 > heapAllocation
Definition juce_BigInteger.h:325
void shiftRight(int bits, int startBit)
Definition juce_BigInteger.cpp:809
void extendedEuclidean(const BigInteger &a, const BigInteger &b, BigInteger &xOut, BigInteger &yOut)
Definition juce_BigInteger.cpp:988
void setRange(int startBit, int numBits, bool shouldBeSet)
Definition juce_BigInteger.cpp:321
void shiftBits(int howManyBitsLeft, int startBit)
Definition juce_BigInteger.cpp:858
int getHighestBit() const noexcept
Definition juce_BigInteger.cpp:376
void divideBy(const BigInteger &divisor, BigInteger &remainder)
Definition juce_BigInteger.cpp:563
String toString(int base, int minimumNumCharacters=1) const
Definition juce_BigInteger.cpp:1081
int findNextClearBit(int startIndex) const noexcept
Definition juce_BigInteger.cpp:398
int compare(const BigInteger &other) const noexcept
Definition juce_BigInteger.cpp:728
BigInteger()
Definition juce_BigInteger.cpp:54
size_t allocatedSize
Definition juce_BigInteger.h:327
void negate() noexcept
Definition juce_BigInteger.cpp:356
void setBit(int bitNumber)
Definition juce_BigInteger.cpp:288
void setBitRangeAsInt(int startBit, int numBits, uint32 valueToSet)
Definition juce_BigInteger.cpp:261
int findNextSetBit(int startIndex) const noexcept
Definition juce_BigInteger.cpp:387
uint32 * ensureSize(size_t)
Definition juce_BigInteger.cpp:173
void loadFromMemoryBlock(const MemoryBlock &data)
Definition juce_BigInteger.cpp:1188
bool isZero() const noexcept
Definition juce_BigInteger.cpp:336
int countNumberOfSetBits() const noexcept
Definition juce_BigInteger.cpp:365
void swapWith(BigInteger &) noexcept
Definition juce_BigInteger.cpp:133
void montgomeryMultiplication(const BigInteger &other, const BigInteger &modulus, const BigInteger &modulusp, int k)
Definition juce_BigInteger.cpp:968
bool isNegative() const noexcept
Definition juce_BigInteger.cpp:346
int highestBit
Definition juce_BigInteger.h:328
int compareAbsolute(const BigInteger &other) const noexcept
Definition juce_BigInteger.cpp:741
void insertBit(int bitNumber, bool shouldBeSet)
Definition juce_BigInteger.cpp:327
int toInteger() const noexcept
Definition juce_BigInteger.cpp:204
void inverseModulo(const BigInteger &modulus)
Definition juce_BigInteger.cpp:1025
Definition juce_HeapBlock.h:87
Definition juce_MemoryBlock.h:33
Definition juce_OutputStream.h:38
Definition juce_String.h:53
Definition juce_StringRef.h:62
register unsigned k
Definition inflate.c:946
static PuglViewHint int value
Definition pugl.h:1708
JSAMPIMAGE data
Definition jpeglib.h:945
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition juce_LeakedObjectDetector.h:138
#define JUCE_CALLTYPE
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
unsigned int uint32
Definition juce_MathsFunctions.h:45
long long int64
Definition juce_MathsFunctions.h:54
signed int int32
Definition juce_MathsFunctions.h:43
const char * text
Definition swell-functions.h:167
b
Definition crypt.c:628
#define const
Definition zconf.h:137