Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::FPLargeInt Class Reference

Class for managing a very large integer for double precision. More...

Public Types

typedef uint32_t ChunkSize_t
 Size of each data chunk.
 
typedef uint64_t MathSize_t
 Size of data chunk for math (Double size of ChunkSize_t)
 

Public Member Functions

 FPLargeInt (void) noexcept
 Default constructor.
 
 FPLargeInt (uint32_t uBitsNeeded) noexcept
 Constructor that sets to a default.
 
uint_t is_zero (void) const noexcept
 Returns TRUE if the value is zero.
 
uint_t is_not_zero (void) const noexcept
 Returns TRUE if the value is not zero.
 
void init (uint32_t uBitsNeeded) noexcept
 Initialize the giant integer.
 
void insert_bits_at_end (uint32_t uBits, uint32_t uShiftAmount) noexcept
 Insert bits into the buffer.
 
void insert_bits_at_start (uint32_t uBits, uint32_t uShiftAmount) noexcept
 Insert bits into the buffer from the top.
 
uint32_t divide_return_remainder (uint32_t uDivisor) noexcept
 Divide the long number and return the remainder.
 
uint32_t multiply_return_overflow (uint32_t uMultiplier) noexcept
 Multiply by multiplier and return the overflow, from 0 to div-1.
 

Static Public Attributes

static constexpr const uint32_t kBitsPerElement
 Number of bits per uint32_t.
 
static constexpr const uint32_t kTotalBitsInTable = 1024 + 64
 Number of bits in the table to handle double precision.
 
static constexpr const uint32_t kMaxElements
 Number of elements in the data table.
 

Protected Member Functions

void insert_chunk_bits (ChunkSize_t uBits, uint32_t uEntryIndex) noexcept
 Do the actual work of inserting bits, and updating zero flag, and extents.
 

Protected Attributes

uint32_t m_uEntryCount
 Number of entries in the data table.
 
int32_t m_iHighestNonZeroElement
 Highest index with a non-zero entry in the data table.
 
int32_t m_iLowestNonZeroElement
 Lowest index with a non-zero entry in the data table.
 
uint32_t m_bIsZero
 TRUE if a zero length buffer
 
ChunkSize_t m_uDataTable [kMaxElements]
 Data table of bits for locating digits.
 

Detailed Description

Class for managing a very large integer for double precision.


This class is useful in parsing high precision numbers and can help in decoding floating point numbers for eventual conversion into a string. A double has up to 2048+53 bits of precision with half in the integer range and the other half in the fractional range. This class handles 1024+64 bits to be able to handle the entire fractional or integer range for ultra high precision double to ASCII conversion.

It can perform modulo and multiplication across all bits of precision. Since this class was designed for high precision integer to ASCII conversion, the two main functions are multiply_return_overflow() to parse out digits from the fractional side of a fixed point number and divide_return_remainder() to extract digits from the integer side of the fixed point number.

Member Typedef Documentation

◆ ChunkSize_t

Size of each data chunk.

◆ MathSize_t

Size of data chunk for math (Double size of ChunkSize_t)

Constructor & Destructor Documentation

◆ FPLargeInt() [1/2]

Burger::FPLargeInt::FPLargeInt ( void )
noexcept

Default constructor.


◆ FPLargeInt() [2/2]

Burger::FPLargeInt::FPLargeInt ( uint32_t uBitsNeeded)
explicitnoexcept

Constructor that sets to a default.


Parameters
uBitsNeededNumber of bits of precision
See also
init(uint32_t)

Member Function Documentation

◆ divide_return_remainder()

uint32_t Burger::FPLargeInt::divide_return_remainder ( uint32_t uDivisor)
noexcept

Divide the long number and return the remainder.


Given a value to perform a modulo, perform the modulo and return the remainder and leave the dividend in the data array

If uDivisor was 0, this function does nothing and returns zero

Parameters
uDivisor32 bit unsigned number to divide the long integer
Returns
Value from 0 to uDivisor-1.
See also
multiply_return_overflow(uint32_t)

◆ init()

void BURGER_API Burger::FPLargeInt::init ( uint32_t uBitsNeeded)
noexcept

Initialize the giant integer.


Reset the giant integer to defaults assuming a bit size

The maximum input value is kTotalBitsInTable -1

Parameters
uBitsNeededNumber of bits of precision 1 through ( kTotalBitsInTable -1)
See also
FPLargeInt(uint32_t)

◆ insert_bits_at_end()

void BURGER_API Burger::FPLargeInt::insert_bits_at_end ( uint32_t uBits,
uint32_t uShiftAmount )
noexcept

Insert bits into the buffer.


Insert the bits from value into m_uDataTable, shifted in from the end of the array by the specified number of bits. A shift of zero or less means that none of the bits will be shifted in. A shift of one means that the high bit of value will be in the bottom of the last element of m_uDataTable; the least significant bit. A shift of kBitsPerElement means that value will be in the least significant element of m_uDataTable, and so on. It's possible a large value can be shifted out.

Parameters
uBits32 bit data to shift in.
uShiftAmountNumber of bits to shift (0 to kTotalBitsInTable)
See also
insert_bits_at_start(uint32_t, uint32_t) or insert_chunk_bits(ChunkSize_t, uint32_t)

◆ insert_bits_at_start()

void BURGER_API Burger::FPLargeInt::insert_bits_at_start ( uint32_t uBits,
uint32_t uShiftAmount )
noexcept

Insert bits into the buffer from the top.


Insert the bits from value into m_uDataTable, shifted in from the beginning of the array by the specified number of bits. A shift of zero or less means that none of the bits will be shifted in. A shift of one means that the low bit of value will be in the top of the first element of m_uDataTable; the most significant bit. A shift of kBitsPerElement means that value will be in the most significant element of m_uDataTable, and so on.

Parameters
uBits32 bit data to shift in
uShiftAmountNumber of bits to shift (0 to kTotalBitsInTable)
See also
insert_bits_at_end(uint32_t, uint32_t) or insert_chunk_bits(ChunkSize_t, uint32_t)

◆ insert_chunk_bits()

void BURGER_API Burger::FPLargeInt::insert_chunk_bits ( ChunkSize_t uBits,
uint32_t uEntryIndex )
protectednoexcept

Do the actual work of inserting bits, and updating zero flag, and extents.


Parameters
uBits32 bit data to shift in
uEntryIndexIndex into the entry table
See also
InsertLowBits(uint32_t, uint32_t) or InsertTopBits(uint32_t, uint32_t)

◆ is_not_zero()

uint_t Burger::FPLargeInt::is_not_zero ( void ) const
inlinenoexcept

Returns TRUE if the value is not zero.


If the giant integer's value is not zero, return TRUE

Returns
TRUE if not zero
See also
is_zero(void) const

◆ is_zero()

uint_t Burger::FPLargeInt::is_zero ( void ) const
inlinenoexcept

Returns TRUE if the value is zero.


If the giant integer's value is zero, return TRUE

Returns
TRUE if zero
See also
is_not_zero(void) const

◆ multiply_return_overflow()

uint32_t Burger::FPLargeInt::multiply_return_overflow ( uint32_t uMultiplier)
noexcept

Multiply by multiplier and return the overflow, from 0 to div-1.


Multiply the giant integer with a number and return the number that overflowed out.

Parameters
uMultiplierValue to multiply the giant integer with
Returns
Overflow value, or zero if there was no overflow or the giant integer was zero.
See also
divide_return_remainder(uint32_t)

Member Data Documentation

◆ kBitsPerElement

const uint32_t Burger::FPLargeInt::kBitsPerElement
staticconstexpr
Initial value:
=
static_cast<uint_t>(sizeof(ChunkSize_t)) * 8
unsigned int uint_t
Unsigned integer.
Definition burger.h:1524
uint32_t ChunkSize_t
Size of each data chunk.
Definition burger.h:6034

Number of bits per uint32_t.

◆ kMaxElements

const uint32_t Burger::FPLargeInt::kMaxElements
staticconstexpr
Initial value:
=
static constexpr const uint32_t kTotalBitsInTable
Number of bits in the table to handle double precision.
Definition burger.h:6047
static constexpr const uint32_t kBitsPerElement
Number of bits per uint32_t.
Definition burger.h:6043

Number of elements in the data table.

◆ kTotalBitsInTable

const uint32_t Burger::FPLargeInt::kTotalBitsInTable = 1024 + 64
staticconstexpr

Number of bits in the table to handle double precision.

◆ m_bIsZero

uint32_t Burger::FPLargeInt::m_bIsZero
protected

TRUE if a zero length buffer

◆ m_iHighestNonZeroElement

int32_t Burger::FPLargeInt::m_iHighestNonZeroElement
protected

Highest index with a non-zero entry in the data table.

◆ m_iLowestNonZeroElement

int32_t Burger::FPLargeInt::m_iLowestNonZeroElement
protected

Lowest index with a non-zero entry in the data table.

◆ m_uDataTable

ChunkSize_t Burger::FPLargeInt::m_uDataTable[kMaxElements]
protected

Data table of bits for locating digits.

◆ m_uEntryCount

uint32_t Burger::FPLargeInt::m_uEntryCount
protected

Number of entries in the data table.