Mstdlib-1.24.0
|
Data Structures | |
struct | M_decimal_t |
Enumerations | |
enum | M_DECIMAL_RETVAL { M_DECIMAL_SUCCESS = 0 , M_DECIMAL_OVERFLOW = 1 , M_DECIMAL_TRUNCATION = 2 , M_DECIMAL_INVALID = 3 } |
enum | M_decimal_round_t { M_DECIMAL_ROUND_NONE = 0 , M_DECIMAL_ROUND_TRADITIONAL = 1 , M_DECIMAL_ROUND_BANKERS = 2 } |
Floating point number type. Used instead of double or float to elimiate rounding errors.
Example:
Example output:
struct M_decimal_t |
enum M_DECIMAL_RETVAL |
Result/Error codes for M_decimal functions.
enum M_decimal_round_t |
void M_decimal_create | ( | M_decimal_t * | dec | ) |
Create new zero'd out decimal number.
[out] | dec | New decimal output. |
void M_decimal_from_int | ( | M_decimal_t * | dec, |
M_int64 | integer, | ||
M_uint8 | implied_dec | ||
) |
Convert to a decimal representation from an integer
[out] | dec | New decimal output. |
[in] | integer | Integer to convert to decimal. |
[in] | implied_dec | Number of implied decimals in integer input. |
M_int64 M_decimal_to_int | ( | const M_decimal_t * | dec, |
M_uint8 | implied_dec | ||
) |
Convert from a decimal representation to an integer with implied decimal places. If the conversion causes truncation, the number will be rounded. For example a decimal of 123.456, with implied decimals 2, will return 12346.
[in] | dec | Decimal type |
[in] | implied_dec | Number of implied decimal positions. |
enum M_DECIMAL_RETVAL M_decimal_from_str | ( | const char * | string, |
size_t | len, | ||
M_decimal_t * | val, | ||
const char ** | endptr | ||
) |
Convert to a decimal representation from a string.
[in] | string | Buffer with decimal representation. |
[in] | len | Length of bytes to evaluate from string. |
[out] | val | New decimal output. |
[out] | endptr | Pointer to end of evaluated decimal. |
enum M_DECIMAL_RETVAL M_decimal_to_str | ( | const M_decimal_t * | dec, |
char * | buf, | ||
size_t | buf_len | ||
) |
Convert from a decimal representation to a string.
[in] | dec | Decimal type. |
[out] | buf | Buffer to output string representation. |
[in] | buf_len | Length of output buffer. |
M_int8 M_decimal_cmp | ( | const M_decimal_t * | dec1, |
const M_decimal_t * | dec2 | ||
) |
Compare 2 decimals.
[in] | dec1 | Decimal 1. |
[in] | dec2 | Decimal 2. |
enum M_DECIMAL_RETVAL M_decimal_transform | ( | M_decimal_t * | dec, |
M_uint8 | num_dec, | ||
M_decimal_round_t | round | ||
) |
Transform decimal number representation to have the specified number of decimal places (rounding if needed).
[in,out] | dec | Decimal type. |
[in] | num_dec | Number of decimal places number should be transformed to. |
[in] | round | Round method to use when rounding. |
void M_decimal_reduce | ( | M_decimal_t * | dec | ) |
Reduce the decimal representation to the smallest number of decimal places possible without reducing precision (remove trailing zeros).
[in,out] | dec | Decimal type. |
M_uint8 M_decimal_num_decimals | ( | const M_decimal_t * | dec | ) |
Number of decimal places present in the M_decimal_t representation.
[in] | dec | Decimal type. |
void M_decimal_duplicate | ( | M_decimal_t * | dest, |
const M_decimal_t * | src | ||
) |
Copy the decimal object from the source into the destination
[out] | dest | New decimal duplicated from src. |
[in] | src | Decimal type to copy. |
enum M_DECIMAL_RETVAL M_decimal_multiply | ( | M_decimal_t * | dest, |
const M_decimal_t * | dec1, | ||
const M_decimal_t * | dec2 | ||
) |
Multiply the two decimals together putting the result in dest.
The destination and one of the sources may be the same. The number of resulting decimal places will be the same as the largest input.
[out] | dest | New decimal with result. |
[in] | dec1 | First decimal to multiply. |
[in] | dec2 | Second decimal to multiply. |
enum M_DECIMAL_RETVAL M_decimal_divide | ( | M_decimal_t * | dest, |
const M_decimal_t * | dec1, | ||
const M_decimal_t * | dec2, | ||
M_decimal_round_t | round | ||
) |
Divide the two decimals, putting the result in dest.
The destination and one of the sources may be the same. The maximum number of decimal places able to be represented will be.
[out] | dest | New decimal with result. |
[in] | dec1 | First decimal (numerator). |
[in] | dec2 | Second decimal (denominator). |
[in] | round | The result may not be able to be represented fully, select the rounding method if truncated. |
enum M_DECIMAL_RETVAL M_decimal_subtract | ( | M_decimal_t * | dest, |
const M_decimal_t * | dec1, | ||
const M_decimal_t * | dec2 | ||
) |
Subtract two decimals, putting the result in dest.
The destination and one of the sources may be the same. The number of resulting decimal places will be the same as the largest input.
[out] | dest | New decimal with result. |
[in] | dec1 | First decimal. |
[in] | dec2 | Second decimal. |
enum M_DECIMAL_RETVAL M_decimal_add | ( | M_decimal_t * | dest, |
const M_decimal_t * | dec1, | ||
const M_decimal_t * | dec2 | ||
) |
Add two decimals, putting the result in dest.
The destination and one of the sources may be the same. The number of resulting decimal places will be the same as the largest input.
[out] | dest | New decimal with result. |
[in] | dec1 | First decimal. |
[in] | dec2 | Second decimal. |