Aesi Multiprecision
C++ class library of long integer arithmetic for GPU parallelization
Typedefs | Functions | Variables
Aeu.h File Reference

Long precision unsigned integer with arithmetic operations. More...

Go to the source code of this file.

Typedefs

using Aeu128 = Aeu< 128 >
 Number with precision 128-bit.
 
using Aeu256 = Aeu< 256 >
 Number with precision 128-bit.
 
using Aeu512 = Aeu< 512 >
 Number with precision 512-bit.
 
using Aeu768 = Aeu< 768 >
 Number with precision 768-bit.
 
using Aeu1024 = Aeu< 1024 >
 Number with precision 1024-bit.
 
using Aeu1536 = Aeu< 1536 >
 Number with precision 1536-bit.
 
using Aeu2048 = Aeu< 2048 >
 Number with precision 2048-bit.
 
using Aeu3072 = Aeu< 3072 >
 Number with precision 3072-bit.
 
using Aeu4096 = Aeu< 4096 >
 Number with precision 4096-bit.
 
using Aeu6144 = Aeu< 6144 >
 Number with precision 6144-bit.
 
using Aeu8192 = Aeu< 8192 >
 Number with precision 8192-bit.
 

Functions

template<std::size_t bitness = 512>
 requires (bitness % blockBitLength==0) class Aeu final
 
template<std::size_t bitness, typename Integral >
 requires (std::is_integral_v< Integral >) gpu const expr auto operator+(Integral number
 Integral conversion addition operator. More...
 
template<std::size_t bitness, typename Integral >
 requires (std::is_integral_v< Integral >) gpu const expr auto operator&(Integral number
 Integral conversion bitwise AND operator. More...
 

Variables

const Aeu< bitness > &value noexcept { return Aeu<bitness>(number) + value
 

Detailed Description

Long precision unsigned integer with arithmetic operations.

Function Documentation

◆ requires() [1/3]

template<std::size_t bitness = 512>
requires ( bitness %  blockBitLength = = 0)
final

Block line of the number

Makes line addition

Parameters
dstBlockLine
srcBlockLine
Returns
Uint64 - carry out from addition

Makes complement block line for line

Parameters
lineBlockLine
Returns
BlockLine

Default constructor

Copy constructor

Copy assignment operator

Parameters
otherAeu

Integral constructor

Parameters
valueIntegral

Accepts both signed and unsigned built-in integral types. When calling this constructor on negative value, final blocks would be inverted.

Note
Be aware of calling this constructor explicitly

Pointer-based character constructor

Parameters
dataChar*
sizeSize_t

Accepts decimal strings (no prefix), binary (0b/0B), octal (0o/0O) and hexadecimal (0x/0X)

C-style string literal constructor

Parameters
literalChar[]

Accepts decimal literals along with binary (starting with 0b/0B), octal (0o/0O) and hexadecimal (0x/0X)

String or string-view based constructor

Parameters
stringViewString/String-View

Constructs object from STD::Basic_String or STD::Basic_String_View. Accepts objects based on char or wchar_t

Unary plus operator

Returns
Aeu
Note
Does basically nothing

Unary minus operator

Returns
Aeu

Prefix increment

Returns
Aeu&

Postfix increment

Returns
Aeu

Prefix decrement

Returns
Aeu&

Postfix decrement

Returns
Aeu

Addition operator for built-in integral types

Parameters
addendumUnsigned
Returns
Aeu

Addition operator

Parameters
addendumAeu
Returns
Aeu

Assignment addition operator for built-in integral types

Parameters
addendumUnsigned
Returns
Aeu&

Assignment addition operator

Parameters
addendumAeu
Returns
Aeu&

Subtraction operator

Parameters
subtrahendAeu
Returns
Aeu

Assignment subtraction operator

Parameters
subtrahendAeu
Returns
Aeu&

Multiplication operator for built-in integral types

Parameters
factorUnsigned
Returns
Aeu

Multiplication operator

Parameters
factorAeu
Returns
Aeu

Assignment multiplication operator for built-in integral types

Parameters
factorUnsigned
Returns
Aeu&

Works with the greatest performance with types smaller than uint64_t

Assignment multiplication operator

Parameters
factorAeu
Returns
Aeu&

Division operator

Parameters
divisorAeu
Returns
Aeu
Note
Undefined behaviour for division by zero

Assignment division operator

Parameters
divisorAeu
Returns
Aeu&
Note
Undefined behaviour for division by zero

Modulo operator

Parameters
moduloAeu
Returns
Aeu

Assignment modulo operator

Parameters
moduloAeu
Returns
Aeu&

Bitwise complement operator

Returns
Aeu

Bitwise XOR operator

Parameters
otherAeu
Returns
Aeu

Assignment bitwise XOR operator

Parameters
otherAeu
Returns
Aeu&

Bitwise AND operator

Parameters
otherAeu
Returns
Aeu

Assignment bitwise AND operator

Parameters
otherAeu
Returns
Aeu&

Bitwise OR operator

Parameters
otherAeu
Returns
Aeu

Assignment bitwise OR operator

Parameters
otherAeu
Returns
Aeu&

Left shift operator

Parameters
bitShiftUnsigned
Returns
Aeu
Note
Does nothing for shift greater than precision

Left shift assignment operator

Parameters
bitShiftUnsigned
Returns
Aeu&
Note
Does nothing for shift greater than precision

Right shift operator

Parameters
bitShiftUnsigned
Returns
Aeu
Note
Does nothing for shift greater than precision

Right shift assignment operator

Parameters
bitShiftUnsigned
Returns
Aeu&
Note
Does nothing for shift greater than precision

Equality check operator for built-in types uint8_t, uint16_t, uint32_t

Parameters
otherUnsigned
Returns
Boolean

Equality check operator for numbers of the same precision

Parameters
otherAeu
Returns
Boolean

Templated Equality check operator for numbers of different precision

Parameters
otherAeu
Returns
Boolean

Internal comparison operator for built-in integral types uint8_t, uint16_t, uint32_t

Parameters
otherUnsigned
Returns
Comparison
Note
Should almost never return Comparison::Equivalent

Internal comparison operator for type uint64_t

Parameters
otheruint64_t
Returns
Comparison
Note
Should almost never return Comparison::Equivalent

Internal comparison operator

Parameters
otherAeu
Returns
Comparison
Note
Should almost never return Comparison::Equivalent

Three-way comparison operator

Parameters
otherAeu
Returns
Std::Strong_ordering
Note
Available from C++20 standard and further. Should almost never return Strong_ordering::Equivalent

Three-way comparison operator for numbers of different precision and built-in integral types

Parameters
otherIntegral
Returns
Std::Strong_ordering
Note
Available from C++20 standard and further. Should almost never return Strong_ordering::Equivalent

Set bit in number by index starting from the right

Parameters
indexSize_t
bitBoolean
Note
Does nothing for index out of range

Get bit in number by index staring from the right

Parameters
indexSize_t
Returns
Boolean
Note
Returns zero for index out of range

Set byte in number by index starting from the right

Parameters
indexSize_t
byteByte
Note
Does nothing for index out of range

Get byte in number by index starting from the right

Parameters
indexSize_t
Returns
Byte
Note
Returns zero for index out of range

Set block in number by index starting from the right

Parameters
indexSize_t
blockBlock
Note
Does nothing for index out of range. Index check is disabled in unsafe mode.

Get block in number by index starting from the right

Parameters
indexSize_t
Returns
Block
Note
Returns zero for index out of range. Index check is disabled in unsafe mode.

Get amount of non-empty bytes in number right to left

Returns
Size_t

Get amount of non-empty bits in number right to left

Returns
Size_t

Check whether number is odd

Returns
Boolean: true is number is odd and false otherwise

Check whether number is even

Returns
Boolean: true if the number is even and false otherwise

Check whether number is zero

Returns
Boolean: true if the number is zero and false otherwise

Get number of non-empty blocks inside object starting from the right

Returns
Size_t

Get number's precision

Returns
Size_t

Get the number of blocks (length of array of uint32_t integers) inside object

Returns
Size_t

Make swap between two objects

Parameters
otherAeu

Integer division. Returns results by reference

Parameters
numberAeu
divisorAeu
quotientAeu OUT
remainderAeu OUT
Returns
Quotient and remainder by reference

Integer division. Returns results by value

Parameters
numberAeu
divisorAeu
Returns
Pair(Quotient, Remainder)

Extended Euclidean algorithm for greatest common divisor

Parameters
firstAeu
secondAeu
bezoutXAeu OUT
bezoutYAeu OUT
Returns
Aeu

Counts Bézout coefficients along with the greatest common divisor. Returns coefficients by reference

Greatest common divisor

Parameters
firstAeu
secondAeu
Returns
Aeu

Faster version, ignoring bezout coefficients

Least common multiplier

Parameters
firstAeu
secondAeu
Returns
Aeu

Exponentiation by modulo

Parameters
baseAeu
powerAeu
moduloAeu
Returns
Aeu
Note
Be aware of overflow

Accepts power of different precision rather than base and modulo

Fast exponentiation for powers of 2

Parameters
powerSize_t
Returns
Aeu

Returns zero for power greater than current bitness

Get square root

Returns
Aeu
Note
Returns zero for negative value or zero

Character buffer output operator

Parameters
bufferChar*
bufferSizeSize_t
showBaseBoolean
hexUppercaseBoolean
Returns
Size_t - amount of symbols written

Places the maximum possible amount of number's characters in buffer. Base parameter should be 2, 8, 10, or 16

Note
Works significantly faster for hexadecimal notation

STD stream output operator

Parameters
osOstream
numberAeu
Returns
Ostream

Writes number in stream. Accepts STD streams based on char or wchar_t. Supports stream manipulators:

  • Number's notation (std::hex, std::dec, std::oct);
  • Number's base (std::showbase);
  • Hexadecimal letters case (std::uppercase, std::lowercase)
    Note
    Works significantly faster for hexadecimal notation
    STD stream binary reading operator
    Parameters
    isIstream
    bigEndianBoolean
    Returns
    Aeu
    Reads number from stream using .read method. Accepts STD streams based on char or wchar_t.
    Note
    Fills empty bits with 0s on EOF of the stream
    STD stream binary writing operator
    Parameters
    osOstream
    bigEndianBoolean
    Writes number in stream using .write method. Accepts STD streams based on char or wchar_t.

Integral type cast operator for built-in types

Returns
Integral

Takes the lowest part of Aeu for conversion. Accepts signed and unsigned types

Precision cast operator

Returns
Aeu<new_bitness>

If required precision greater than current precision, remaining blocks are filled with zeros. Otherwise - number is cropped inside smaller blocks array

Note
Using this method directly is not recommended, cause it leads to redundant copying and may be slow

◆ requires() [2/3]

template<std::size_t bitness, typename Integral >
requires ( std::is_integral_v< Integral >  ) const

Integral conversion addition operator.

Integral conversion bitwise OR operator.

Integral conversion bitwise XOR operator.

Integral conversion modulo operator.

Integral conversion division operator.

Integral conversion multiplication operator.

Integral conversion subtraction operator.

Parameters
numberIntegral
valueAeu
Returns
Aeu

◆ requires() [3/3]

template<std::size_t bitness, typename Integral >
requires ( std::is_integral_v< Integral >  ) const &

Integral conversion bitwise AND operator.

Parameters
numberIntegral
valueAeu
Returns
Aeu