BigIntegerInterface Class Reference Data Types

#include <big_integer.h>

详细描述

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}

公共成员函数

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 < Bool IsProbablyPrime ( 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 >  添加 (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 < Bool MultiplicativeInverse (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   比较 (const BigIntegerInterface *arg2) const
MAXON_METHOD HashInt   GetHashCode () const
MAXON_METHOD String   ToString (const FormatStatement *formatStatement=nullptr) const

静态公共成员函数

static MAXON_METHOD BigIntegerInterface Zero ()
static MAXON_METHOD BigIntegerInterface One ()
static MAXON_METHOD BigIntegerInterface MinusOne ()
static MAXON_METHOD Result < void >  DescribeIO (const DataSerializeInterface &stream)

私有成员函数

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

成员函数文档编制

◆  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.

返回
A BigInteger value of zero.

◆  One()

static MAXON_METHOD BigIntegerInterface * One ( )
static

Returns a BigInteger value of one.

返回
A BigInteger value of one.

◆  MinusOne()

static MAXON_METHOD BigIntegerInterface * MinusOne ( )
static

Returns a BigInteger value of minus one.

返回
A BigInteger value of minus one.

◆  Set() [1/10]

MAXON_METHOD Result <void> Set ( Char   c )

Sets the value of this BigInteger .

参数
[in] c The new value.
返回
OK on success.

◆  Set() [2/10]

MAXON_METHOD Result <void> Set ( UChar   c )

Sets the value of this BigInteger .

参数
[in] c The new value.
返回
OK on success.

◆  Set() [3/10]

MAXON_METHOD Result <void> Set ( Int16   i )

Sets the value of this BigInteger .

参数
[in] i The new value.
返回
OK on success.

◆  Set() [4/10]

MAXON_METHOD Result <void> Set ( UInt16   u )

Sets the value of this BigInteger .

参数
[in] u The new value.
返回
OK on success.

◆  Set() [5/10]

MAXON_METHOD Result <void> Set ( Int32   i )

Sets the value of this BigInteger .

参数
[in] i The new value.
返回
OK on success.

◆  Set() [6/10]

MAXON_METHOD Result <void> Set ( UInt32   u )

Sets the value of this BigInteger .

参数
[in] u The new value.
返回
OK on success.

◆  Set() [7/10]

MAXON_METHOD Result <void> Set ( Int64   i )

Sets the value of this BigInteger .

参数
[in] i The new value.
返回
OK on success.

◆  Set() [8/10]

MAXON_METHOD Result <void> Set ( UInt64   u )

Sets the value of this BigInteger .

参数
[in] u The new value.
返回
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.

参数
[in] bitCount The number of bits to set. This value must be greater than 0.
[in] provider A secure random provider that can be used with SecureRandom . If nullptr is passed an unsecure default provider is chosen.
返回
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.

参数
[in] bitCount The number of bits to set. This value must be greater than 1.
[in] certainty The 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] provider A secure random provider that can be used with SecureRandom . If nullptr is passed an unsecure default provider is chosen.
返回
OK on success.

◆  Set() [9/10]

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

Sets the value of this BigInteger .

参数
[in] mem A memory block that contains the new value in the specified format.
[in] littleEndian If this value is true, the parameter is treated as little-endian ("Intel format"), otherwise big-endian ("Motorola format").
返回
OK on success.

◆  Set() [10/10]

MAXON_METHOD Result <void> Set ( const String str )

Sets the value of this BigInteger .

参数
[in] str The new value, represented as a decimal string. The string may only contain decimal digits.
返回
OK on success.

◆  SetHex()

MAXON_METHOD Result <void> SetHex ( const String str )

Sets the value of this BigInteger .

参数
[in] str The new value, represented as a hexadecimal string. The string may only contain hexadecimal digits.
返回
OK on success.

◆  IsEven()

MAXON_METHOD Bool IsEven ( ) const

Checks if the value is even.

返回
True if the value is even, false otherwise.

◆  IsOdd()

MAXON_METHOD Bool IsOdd ( ) const

Checks if the value is odd.

返回
True if the value is odd, false otherwise.

◆  IsOne()

MAXON_METHOD Bool IsOne ( ) const

Checks if the value is one.

返回
True if the value is one, false otherwise.

◆  IsZero()

MAXON_METHOD Bool IsZero ( ) const

Checks if the value is zero.

返回
True if the value is zero, false otherwise.

◆  IsNegative()

MAXON_METHOD Bool IsNegative ( ) const

Checks if the value is negative.

返回
True if the value is negative, false otherwise.

◆  IsPowerOfTwo()

MAXON_METHOD Bool IsPowerOfTwo ( ) const

Checks if the value is a power of 2.

返回
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.

参数
[in] certainty The certainty with which the number is checked for being a prime number. This parameter must be greater than 0.
返回
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.

返回
-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.

返回
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.

返回
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.

返回
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.

参数
[in] bit The bit position to set.
返回
True, if the bit is set, false otherwise.

◆  GetLowestBits8U()

MAXON_METHOD UChar GetLowestBits8U ( ) const

Get the lowest 8 bits.

返回
The lowest 8 bits as an unsigned 8-bit integer.

◆  GetLowestBits8S()

MAXON_METHOD Char GetLowestBits8S ( ) const

Get the lowest 8 bits.

返回
The lowest 8 bits as an signed 8-bit integer.

◆  GetLowestBits16U()

MAXON_METHOD UInt16 GetLowestBits16U ( ) const

Get the lowest 16 bits.

返回
The lowest 16 bits as an unsigned 16-bit integer.

◆  GetLowestBits16S()

MAXON_METHOD Int16 GetLowestBits16S ( ) const

Get the lowest 16 bits.

返回
The lowest 16 bits as an signed 16-bit integer.

◆  GetLowestBits32U()

MAXON_METHOD UInt32 GetLowestBits32U ( ) const

Get the lowest 32 bits.

返回
The lowest 32 bits as an unsigned 32-bit integer.

◆  GetLowestBits32S()

MAXON_METHOD Int32 GetLowestBits32S ( ) const

Get the lowest 32 bits.

返回
The lowest 32 bits as an signed 32-bit integer.

◆  GetLowestBits64U()

MAXON_METHOD UInt64 GetLowestBits64U ( ) const

Get the lowest 64 bits.

返回
The lowest 64 bits as an unsigned 64-bit integer.

◆  GetLowestBits64S()

MAXON_METHOD Int64 GetLowestBits64S ( ) const

Get the lowest 64 bits.

返回
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.

参数
[in] littleEndian If this value is true, the data is written in little-endian format, otherwise big-endian.
[out] data The BaseArray that will hold the data copy in the specified format.
返回
OK on success.

◆  Add()

MAXON_METHOD Result <void> Add ( const BigIntegerInterface b )

Performs the add operation.

参数
[in] b The value to add to this.

◆  Sub()

MAXON_METHOD Result <void> Sub ( const BigIntegerInterface b )

Performs the subtract operation.

参数
[in] b The 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.

参数
[in] b The value to multiply to this.

◆  Div()

MAXON_METHOD Result <void> Div ( const BigIntegerInterface b )

Performs the divide operation.

参数
[in] b The 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.

参数
[in] b The 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.

参数
[in] b The 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] r The 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.

参数
[in] b Raises 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.

参数
[in] b Raises this to the power of b. The result will be 0 if b is negative.
[in] mod The 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.

参数
[in] b Another 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.

参数
[in] m Another BigInteger . This value must be greater than zero.
返回
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.

参数
[in] s The 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.

参数
[in] s The 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.

参数
[in] bit The position of the bit which is to set.

◆  ClearBit()

MAXON_METHOD Result <void> ClearBit ( Int   bit )

Clears a bit in the integer.

参数
[in] bit The position of the bit which is to clear.

◆  ToggleBit()

MAXON_METHOD Result <void> ToggleBit ( Int   bit )

Toggles a bit in the integer.

参数
[in] bit The position of the bit which is to toggle.

◆  Compare()

MAXON_METHOD COMPARERESULT 比较 ( const BigIntegerInterface arg2 ) const

Compares this with another BigInteger 值。

参数
[in] arg2 The other BigInteger value to compare with.
返回
The comparison result.

◆  GetHashCode()

MAXON_METHOD HashInt GetHashCode ( ) const

Returns the hash code of the object.

◆  ToString()

MAXON_METHOD String ToString ( const FormatStatement formatStatement = nullptr ) const

Returns a readable string of the content.

参数
[in] formatStatement Nullptr or additional formatting instruction. Currently no additional formatting instructions are supported.
返回
The converted result.

◆  DescribeIO()

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

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

参数
[in] stream The stream that is used to register the class members.
返回
OK on success.