BigIntegerInterface Class Reference

#include <big_integer.h>

Detailed Description

This is the interface for the BigInteger data type. The data is reference-counted and a copy will automatically be created if a non-const function is called.

@MAXON_ANNOTATION{refclass=false}

Public Member Functions

MAXON_METHOD Result< void > Set (Char c)
 
MAXON_METHOD Result< void > Set (UChar c)
 
MAXON_METHOD Result< void > Set (Int16 i)
 
MAXON_METHOD Result< void > Set (UInt16 u)
 
MAXON_METHOD Result< void > Set (Int32 i)
 
MAXON_METHOD Result< void > Set (UInt32 u)
 
MAXON_METHOD Result< void > Set (Int64 i)
 
MAXON_METHOD Result< void > Set (UInt64 u)
 
MAXON_METHOD Result< void > SetRandom (Int bitCount, SecureRandomProvider provider=SecureRandomProvider())
 
MAXON_METHOD Result< void > SetRandomPrime (Int bitCount, UInt certainty, SecureRandomProvider provider=SecureRandomProvider())
 
MAXON_METHOD Result< void > Set (const Block< const Byte > &mem, Bool littleEndian)
 
MAXON_METHOD Result< void > Set (const String &str)
 
MAXON_METHOD Result< void > SetHex (const String &str)
 
MAXON_METHOD Bool IsEven () const
 
MAXON_METHOD Bool IsOdd () const
 
MAXON_METHOD Bool IsOne () const
 
MAXON_METHOD Bool IsZero () const
 
MAXON_METHOD Bool IsNegative () const
 
MAXON_METHOD Bool IsPowerOfTwo () const
 
MAXON_METHOD Result< BoolIsProbablyPrime (UInt certainty) const
 
MAXON_METHOD Int Sign () const
 
MAXON_METHOD Int GetHighestNonSignBit () const
 
MAXON_METHOD Int GetLowestSetBit () const
 
MAXON_METHOD Int GetLowestClearedBit () const
 
MAXON_METHOD Bool IsBitSet (Int bit) const
 
MAXON_METHOD UChar GetLowestBits8U () const
 
MAXON_METHOD Char GetLowestBits8S () const
 
MAXON_METHOD UInt16 GetLowestBits16U () const
 
MAXON_METHOD Int16 GetLowestBits16S () const
 
MAXON_METHOD UInt32 GetLowestBits32U () const
 
MAXON_METHOD Int32 GetLowestBits32S () const
 
MAXON_METHOD UInt64 GetLowestBits64U () const
 
MAXON_METHOD Int64 GetLowestBits64S () const
 
MAXON_METHOD Result< void > GetDataCopy (Bool littleEndian, BaseArray< UChar > &data) const
 
MAXON_METHOD Result< void > Add (const BigIntegerInterface *b)
 
MAXON_METHOD Result< void > Sub (const BigIntegerInterface *b)
 
MAXON_METHOD Result< void > Inc ()
 
MAXON_METHOD Result< void > Dec ()
 
MAXON_METHOD Result< void > Mul (const BigIntegerInterface *b)
 
MAXON_METHOD Result< void > Div (const BigIntegerInterface *b)
 
MAXON_METHOD Result< void > Mod (const BigIntegerInterface *b)
 
MAXON_METHOD Result< void > DivMod (const BigIntegerInterface *b, BigInteger &r)
 
MAXON_METHOD Result< void > Pow (const BigIntegerInterface *b)
 
MAXON_METHOD Result< void > PowMod (const BigIntegerInterface *b, const BigIntegerInterface *mod)
 
MAXON_METHOD Result< void > GreatestCommonDivisor (const BigIntegerInterface *b)
 
MAXON_METHOD Result< BoolMultiplicativeInverse (const BigIntegerInterface *m)
 
MAXON_METHOD Result< void > LeftShift (Int s)
 
MAXON_METHOD Result< void > RightShift (Int s)
 
MAXON_METHOD Result< void > Negate ()
 
MAXON_METHOD Result< void > SetBit (Int bit)
 
MAXON_METHOD Result< void > ClearBit (Int bit)
 
MAXON_METHOD Result< void > ToggleBit (Int bit)
 
MAXON_METHOD COMPARERESULT Compare (const BigIntegerInterface *arg2) const
 
MAXON_METHOD UInt GetHashCode () const
 
MAXON_METHOD String ToString (const FormatStatement *formatStatement) const
 

Static Public Member Functions

static MAXON_METHOD BigIntegerInterfaceZero ()
 
static MAXON_METHOD BigIntegerInterfaceOne ()
 
static MAXON_METHOD BigIntegerInterfaceMinusOne ()
 
static MAXON_METHOD Result< void > DescribeIO (const DataSerializeInterface &stream)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (BigIntegerInterface, MAXON_REFERENCE_COPY_ON_WRITE, "net.maxon.interface.biginteger")
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( BigIntegerInterface  ,
MAXON_REFERENCE_COPY_ON_WRITE  ,
"net.maxon.interface.biginteger"   
)
private

◆ Zero()

static MAXON_METHOD BigIntegerInterface* Zero ( )
static

Returns a BigInteger value of zero.

Returns
A BigInteger value of zero.

◆ One()

static MAXON_METHOD BigIntegerInterface* One ( )
static

Returns a BigInteger value of one.

Returns
A BigInteger value of one.

◆ MinusOne()

static MAXON_METHOD BigIntegerInterface* MinusOne ( )
static

Returns a BigInteger value of minus one.

Returns
A BigInteger value of minus one.

◆ Set() [1/10]

MAXON_METHOD Result<void> Set ( Char  c)

Sets the value of this BigInteger.

Parameters
[in]cThe new value.
Returns
OK on success.

◆ Set() [2/10]

MAXON_METHOD Result<void> Set ( UChar  c)

Sets the value of this BigInteger.

Parameters
[in]cThe new value.
Returns
OK on success.

◆ Set() [3/10]

MAXON_METHOD Result<void> Set ( Int16  i)

Sets the value of this BigInteger.

Parameters
[in]iThe new value.
Returns
OK on success.

◆ Set() [4/10]

MAXON_METHOD Result<void> Set ( UInt16  u)

Sets the value of this BigInteger.

Parameters
[in]uThe new value.
Returns
OK on success.

◆ Set() [5/10]

MAXON_METHOD Result<void> Set ( Int32  i)

Sets the value of this BigInteger.

Parameters
[in]iThe new value.
Returns
OK on success.

◆ Set() [6/10]

MAXON_METHOD Result<void> Set ( UInt32  u)

Sets the value of this BigInteger.

Parameters
[in]uThe new value.
Returns
OK on success.

◆ Set() [7/10]

MAXON_METHOD Result<void> Set ( Int64  i)

Sets the value of this BigInteger.

Parameters
[in]iThe new value.
Returns
OK on success.

◆ Set() [8/10]

MAXON_METHOD Result<void> Set ( UInt64  u)

Sets the value of this BigInteger.

Parameters
[in]uThe new value.
Returns
OK on success.

◆ SetRandom()

MAXON_METHOD Result<void> SetRandom ( Int  bitCount,
SecureRandomProvider  provider = SecureRandomProvider() 
)

Assigns a random value to this BigInteger. The number is always positive.

Parameters
[in]bitCountThe number of bits to set. This value must be greater than 0.
[in]providerA secure random provider that can be used with SecureRandom. If nullptr is passed an unsecure default provider is chosen.
Returns
OK on success.

◆ SetRandomPrime()

MAXON_METHOD Result<void> SetRandomPrime ( Int  bitCount,
UInt  certainty,
SecureRandomProvider  provider = SecureRandomProvider() 
)

Assigns a random prime number value to this BigInteger. The number is always positive, odd and the (bitCount - 1) bit will be set.

Parameters
[in]bitCountThe number of bits to set. This value must be greater than 1.
[in]certaintyThe generated number is a prime number with a probability of 1-0.5**certainty. This parameter must be greater than 0. The execution time of this function raises with the certainty.
[in]providerA secure random provider that can be used with SecureRandom. If nullptr is passed an unsecure default provider is chosen.
Returns
OK on success.

◆ Set() [9/10]

MAXON_METHOD Result<void> Set ( const Block< const Byte > &  mem,
Bool  littleEndian 
)

Sets the value of this BigInteger.

Parameters
[in]memA memory block that contains the new value in the specified format.
[in]littleEndianIf this value is true, the parameter is treated as little-endian ("Intel format"), otherwise big-endian ("Motorola format").
Returns
OK on success.

◆ Set() [10/10]

MAXON_METHOD Result<void> Set ( const String str)

Sets the value of this BigInteger.

Parameters
[in]strThe new value, represented as a decimal string. The string may only contain decimal digits.
Returns
OK on success.

◆ SetHex()

MAXON_METHOD Result<void> SetHex ( const String str)

Sets the value of this BigInteger.

Parameters
[in]strThe new value, represented as a hexadecimal string. The string may only contain hexadecimal digits.
Returns
OK on success.

◆ IsEven()

MAXON_METHOD Bool IsEven ( ) const

Checks if the value is even.

Returns
True if the value is even, false otherwise.

◆ IsOdd()

MAXON_METHOD Bool IsOdd ( ) const

Checks if the value is odd.

Returns
True if the value is odd, false otherwise.

◆ IsOne()

MAXON_METHOD Bool IsOne ( ) const

Checks if the value is one.

Returns
True if the value is one, false otherwise.

◆ IsZero()

MAXON_METHOD Bool IsZero ( ) const

Checks if the value is zero.

Returns
True if the value is zero, false otherwise.

◆ IsNegative()

MAXON_METHOD Bool IsNegative ( ) const

Checks if the value is negative.

Returns
True if the value is negative, false otherwise.

◆ IsPowerOfTwo()

MAXON_METHOD Bool IsPowerOfTwo ( ) const

Checks if the value is a power of 2.

Returns
True if the value is a power of 2, false otherwise.

◆ IsProbablyPrime()

MAXON_METHOD Result<Bool> IsProbablyPrime ( UInt  certainty) const

Checks if the number is probably prime. The result will be false if the value of this BigInteger is smaller than one.

Parameters
[in]certaintyThe certainty with which the number is checked for being a prime number. This parameter must be greater than 0.
Returns
True if number is greater than zero and prime with a probability of 1-0.5**certainty.

◆ Sign()

MAXON_METHOD Int Sign ( ) const

Gets the sign.

Returns
-1 if the number is negative, 0 if it is zero, 1 if it is positive.

◆ GetHighestNonSignBit()

MAXON_METHOD Int GetHighestNonSignBit ( ) const

Gets the highest bit position that is different than the sign bit. This is the position incremented by one for negative numbers.

Returns
The bit position. The return value is -1 if the number is 0.

◆ GetLowestSetBit()

MAXON_METHOD Int GetLowestSetBit ( ) const

Gets the lowest bit position that is zero.

Returns
The bit position. The return value is -1 if the number is 0.

◆ GetLowestClearedBit()

MAXON_METHOD Int GetLowestClearedBit ( ) const

Gets the lowest bit position that is zero.

Returns
The bit position. The return value is -1 if the number is -1.

◆ IsBitSet()

MAXON_METHOD Bool IsBitSet ( Int  bit) const

Checks if the bit at a certain position is set.

Parameters
[in]bitThe bit position to set.
Returns
True, if the bit is set, false otherwise.

◆ GetLowestBits8U()

MAXON_METHOD UChar GetLowestBits8U ( ) const

Get the lowest 8 bits.

Returns
The lowest 8 bits as an unsigned 8-bit integer.

◆ GetLowestBits8S()

MAXON_METHOD Char GetLowestBits8S ( ) const

Get the lowest 8 bits.

Returns
The lowest 8 bits as an signed 8-bit integer.

◆ GetLowestBits16U()

MAXON_METHOD UInt16 GetLowestBits16U ( ) const

Get the lowest 16 bits.

Returns
The lowest 16 bits as an unsigned 16-bit integer.

◆ GetLowestBits16S()

MAXON_METHOD Int16 GetLowestBits16S ( ) const

Get the lowest 16 bits.

Returns
The lowest 16 bits as an signed 16-bit integer.

◆ GetLowestBits32U()

MAXON_METHOD UInt32 GetLowestBits32U ( ) const

Get the lowest 32 bits.

Returns
The lowest 32 bits as an unsigned 32-bit integer.

◆ GetLowestBits32S()

MAXON_METHOD Int32 GetLowestBits32S ( ) const

Get the lowest 32 bits.

Returns
The lowest 32 bits as an signed 32-bit integer.

◆ GetLowestBits64U()

MAXON_METHOD UInt64 GetLowestBits64U ( ) const

Get the lowest 64 bits.

Returns
The lowest 64 bits as an unsigned 64-bit integer.

◆ GetLowestBits64S()

MAXON_METHOD Int64 GetLowestBits64S ( ) const

Get the lowest 64 bits.

Returns
The lowest 64 bits as an signed 64-bit integer.

◆ GetDataCopy()

MAXON_METHOD Result<void> GetDataCopy ( Bool  littleEndian,
BaseArray< UChar > &  data 
) const

Gets a copy of the internal data.

Parameters
[in]littleEndianIf this value is true, the data is written in little-endian format, otherwise big-endian.
[out]dataThe BaseArray that will hold the data copy in the specified format.
Returns
OK on success.

◆ Add()

MAXON_METHOD Result<void> Add ( const BigIntegerInterface b)

Performs the add operation.

Parameters
[in]bThe value to add to this.

◆ Sub()

MAXON_METHOD Result<void> Sub ( const BigIntegerInterface b)

Performs the subtract operation.

Parameters
[in]bThe value to subtract to this.

◆ Inc()

MAXON_METHOD Result<void> Inc ( )

Increments the value by one.

◆ Dec()

MAXON_METHOD Result<void> Dec ( )

Decrements the value by one.

◆ Mul()

MAXON_METHOD Result<void> Mul ( const BigIntegerInterface b)

Performs the multiply operation.

Parameters
[in]bThe value to multiply to this.

◆ Div()

MAXON_METHOD Result<void> Div ( const BigIntegerInterface b)

Performs the divide operation.

Parameters
[in]bThe value with which is this to divide. The result is 0, if b is 0 or if its absolute value is bigger than the absolute value of this.

◆ Mod()

MAXON_METHOD Result<void> Mod ( const BigIntegerInterface b)

Performs the modulo operation.

Parameters
[in]bThe modulus. The result is 0, if b is 0.

◆ DivMod()

MAXON_METHOD Result<void> DivMod ( const BigIntegerInterface b,
BigInteger r 
)

Performs the divide and modulo operation.

Parameters
[in]bThe value with which is this to divide. The result is 0, if b is 0 or if its absolute value is bigger than the absolute value of this.
[out]rThe remainder of the division will be stored in r. The value of r is undefined if b is 0.

◆ Pow()

MAXON_METHOD Result<void> Pow ( const BigIntegerInterface b)

Performs the power operation.

Parameters
[in]bRaises this to the power of b. The result will be 0 if b is negative.

◆ PowMod()

MAXON_METHOD Result<void> PowMod ( const BigIntegerInterface b,
const BigIntegerInterface mod 
)

Performs the power operation and takes the result modulo mod.

Parameters
[in]bRaises this to the power of b. The result will be 0 if b is negative.
[in]modThe modulo value.

◆ GreatestCommonDivisor()

MAXON_METHOD Result<void> GreatestCommonDivisor ( const BigIntegerInterface b)

Calculates the greatest common divisor of this and b. Both values must be greater than zero, otherwise the value will remain unchanged.

Parameters
[in]bAnother BigInteger.

◆ MultiplicativeInverse()

MAXON_METHOD Result<Bool> MultiplicativeInverse ( const BigIntegerInterface m)

Calculates the multiplicative inverse of this modulo m. This must be smaller than m. The new result of this will be greater or equal to zero and smaller than m.

Parameters
[in]mAnother BigInteger. This value must be greater than zero.
Returns
True, if there is a multiplicative inverse, false otherwise. The value of this is unchanged if there is no multiplicative inverse.

◆ LeftShift()

MAXON_METHOD Result<void> LeftShift ( Int  s)

Performs the Left shift operation. If the number of bits to shift is less than 0 the bits are shifted right.

Parameters
[in]sThe number of bits to shift.

◆ RightShift()

MAXON_METHOD Result<void> RightShift ( Int  s)

Performs the Right shift operation. If the number of bits to shift is less than 0 the bits are shifted left.

Parameters
[in]sThe number of bits to shift.

◆ Negate()

MAXON_METHOD Result<void> Negate ( )

Negates the value.

◆ SetBit()

MAXON_METHOD Result<void> SetBit ( Int  bit)

Sets a bit in the integer.

Parameters
[in]bitThe position of the bit which is to set.

◆ ClearBit()

MAXON_METHOD Result<void> ClearBit ( Int  bit)

Clears a bit in the integer.

Parameters
[in]bitThe position of the bit which is to clear.

◆ ToggleBit()

MAXON_METHOD Result<void> ToggleBit ( Int  bit)

Toggles a bit in the integer.

Parameters
[in]bitThe position of the bit which is to toggle.

◆ Compare()

MAXON_METHOD COMPARERESULT Compare ( const BigIntegerInterface arg2) const

Compares this with another BigInteger value.

Parameters
[in]arg2The other BigInteger value to compare with.
Returns
The comparison result.

◆ GetHashCode()

MAXON_METHOD UInt GetHashCode ( ) const

Returns the hash code of the object.

◆ ToString()

MAXON_METHOD String ToString ( const FormatStatement formatStatement) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. Currently no additional formatting instructions are supported.
Returns
The converted result.

◆ DescribeIO()

static MAXON_METHOD Result<void> DescribeIO ( const DataSerializeInterface stream)
static

Describe all elements of this class for I/O operations.

Parameters
[in]streamThe stream that is used to register the class members.
Returns
OK on success.