#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 | |
LargeFixedNumber & | operator= (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 () |
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.
|
default |
Create a default instance which needs to be configured before use
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
totalDigits | the maximum digits to use |
decimalPointIndex | the number of decimal places |
whole | the whole value expressed as an unsigned integer |
fraction | the fractional part expressed as a unsigned integer |
negative | if the value is positive or negative |
void LargeFixedNumber::clear | ( | ) |
Clears the whole structure before setting to a new value
|
inline |
|
inline |
|
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.
dp | the new number of decimal places |
maxDigits | the total number of digits needed. |
void LargeFixedNumber::setValue | ( | uint32_t | whole, |
uint32_t | fraction, | ||
bool | negative | ||
) |
Sets the value of this instance without changing the decimal places.
whole | the whole part of the value |
fraction | the fractional part of the value |
negative | if the value to hold is negative. |
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.
value | the float value to convert |
uint32_t LargeFixedNumber::fromBcdPacked | ( | int | start, |
int | end | ||
) |
Converts from the BCD packed structure into an integer
start | the index to start in the packed data |
end | will stop at one before this point |
void LargeFixedNumber::convertToBcdPacked | ( | uint32_t | value, |
int | start, | ||
int | end | ||
) |
Converts from an integer into BCD packed.
value | the value to be encoded |
start | the index to start in the packed data |
end | will stop at one before this point |
int LargeFixedNumber::getDigit | ( | int | digit | ) |
get a particular digit from the bit packed structure.
digit | the number of the digit zero based. |
void LargeFixedNumber::setDigit | ( | int | digit, |
int | val | ||
) |
set a particular digit in the packed structure to a value
digit | the number of the digit zero based |
value | the new value for that digit |
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.
|
inline |
|
inline |
Sets the negative flag, if true the number becomes a negative value.
neg | the new negative flag value |
|
inline |
|
inline |
|
inline |
Gets the underlying buffer to enable storage / loading from EEPROM