tcMenu
Public Member Functions | List of all members
LargeFixedNumber Class Reference

#include <EditableLargeNumberMenuItem.h>

Public Member Functions

 LargeFixedNumber ()=default
 
 LargeFixedNumber (int totalDigits, int decimalPointIndex, uint32_t whole, uint32_t fraction, bool negative)
 
 LargeFixedNumber (const LargeFixedNumber &other)=default
 
LargeFixedNumberoperator= (const LargeFixedNumber &other)=default
 
void clear ()
 
int decimalPointIndex () const
 
int getTotalDigits () const
 
void setPrecision (uint8_t dp, uint8_t maxDigits=12)
 
void setValue (uint32_t whole, uint32_t fraction, bool negative)
 
void setFromFloat (float value)
 
uint32_t fromBcdPacked (int start, int end)
 
void convertToBcdPacked (uint32_t value, int start, int end)
 
int getDigit (int digit)
 
void setDigit (int digit, int val)
 
float getAsFloat ()
 
bool isNegative () const
 
void setNegative (bool neg)
 
uint32_t getWhole ()
 
uint32_t getFraction ()
 
uint8_t * getNumberBuffer ()
 

Detailed Description

A structure for very large numbers that can be edited using the multipart editor. They are represented as binary coded decimal to 12 dp with between 0 and 9 fraction decimal places if needed. The whole can be either negative or positive between 1 and 9 decimal places. Both fraction and whole can be extracted as either a floating point, a per digit value, or as integers containing whole, fraction and negative flag.

Constructor & Destructor Documentation

◆ LargeFixedNumber() [1/2]

LargeFixedNumber::LargeFixedNumber ( )
default

Create a default instance which needs to be configured before use

◆ LargeFixedNumber() [2/2]

LargeFixedNumber::LargeFixedNumber ( int  totalDigits,
int  decimalPointIndex,
uint32_t  whole,
uint32_t  fraction,
bool  negative 
)

Create a fully populated LargeFixedNumber giving the number of digits and the initial value

Parameters
totalDigitsthe maximum digits to use
decimalPointIndexthe number of decimal places
wholethe whole value expressed as an unsigned integer
fractionthe fractional part expressed as a unsigned integer
negativeif the value is positive or negative

Member Function Documentation

◆ clear()

void LargeFixedNumber::clear ( )

Clears the whole structure before setting to a new value

◆ decimalPointIndex()

int LargeFixedNumber::decimalPointIndex ( ) const
inline
Returns
the number of decimal places this represents.

◆ getTotalDigits()

int LargeFixedNumber::getTotalDigits ( ) const
inline
Returns
the total number of digits it can represent

◆ setPrecision()

void LargeFixedNumber::setPrecision ( uint8_t  dp,
uint8_t  maxDigits = 12 
)
inline

Set the number of decimal places and optionally the total size then zero out any currently held value. When setting this value you should ensure that: fractionDp is not larger than 9, the difference between fractionDp and maxDigits is not greater than 9.

Parameters
dpthe new number of decimal places
maxDigitsthe total number of digits needed.

◆ setValue()

void LargeFixedNumber::setValue ( uint32_t  whole,
uint32_t  fraction,
bool  negative 
)

Sets the value of this instance without changing the decimal places.

Parameters
wholethe whole part of the value
fractionthe fractional part of the value
negativeif the value to hold is negative.

◆ setFromFloat()

void LargeFixedNumber::setFromFloat ( float  value)

Takes a floating point value and converts it into the internal representation. This will represent the float within the bounds of the current total digits and decimal precision.

Parameters
valuethe float value to convert

◆ fromBcdPacked()

uint32_t LargeFixedNumber::fromBcdPacked ( int  start,
int  end 
)

Converts from the BCD packed structure into an integer

Parameters
startthe index to start in the packed data
endwill stop at one before this point
Returns
the integer value

◆ convertToBcdPacked()

void LargeFixedNumber::convertToBcdPacked ( uint32_t  value,
int  start,
int  end 
)

Converts from an integer into BCD packed.

Parameters
valuethe value to be encoded
startthe index to start in the packed data
endwill stop at one before this point

◆ getDigit()

int LargeFixedNumber::getDigit ( int  digit)

get a particular digit from the bit packed structure.

Parameters
digitthe number of the digit zero based.
Returns
the number at this location

◆ setDigit()

void LargeFixedNumber::setDigit ( int  digit,
int  val 
)

set a particular digit in the packed structure to a value

Parameters
digitthe number of the digit zero based
valuethe new value for that digit

◆ getAsFloat()

float LargeFixedNumber::getAsFloat ( )

Gets the value converted to a float, note that floats cannot represent all values accurately and as such this will be the nearest float that represents the value. With numbers that get close to the 12 digit range it is highly possible that the float will be inaccurate.

Returns
the current represented value as a floating point number.

◆ isNegative()

bool LargeFixedNumber::isNegative ( ) const
inline
Returns
true if negative otherwise false.

◆ setNegative()

void LargeFixedNumber::setNegative ( bool  neg)
inline

Sets the negative flag, if true the number becomes a negative value.

Parameters
negthe new negative flag value

◆ getWhole()

uint32_t LargeFixedNumber::getWhole ( )
inline
Returns
the whole part of the value

◆ getFraction()

uint32_t LargeFixedNumber::getFraction ( )
inline
Returns
the fractional part of the value

◆ getNumberBuffer()

uint8_t* LargeFixedNumber::getNumberBuffer ( )
inline

Gets the underlying buffer to enable storage / loading from EEPROM

Returns
the underlying bcd buffer

The documentation for this class was generated from the following files: