MySQL 8.0.39
Source Code Documentation
|
Go to the source code of this file.
Classes | |
struct | decimal_t |
intg is the number of decimal digits (NOT number of decimal_digit_t's !) before the point frac is the number of decimal digits after the point len is the length of buf (length of allocated space) in decimal_digit_t's, not in bytes sign false means positive, true means negative buf is an array of decimal_digit_t's More... | |
Macros | |
#define | E_DEC_OK 0 |
#define | E_DEC_TRUNCATED 1 |
#define | E_DEC_OVERFLOW 2 |
#define | E_DEC_DIV_ZERO 4 |
#define | E_DEC_BAD_NUM 8 |
#define | E_DEC_OOM 16 |
#define | E_DEC_FATAL_ERROR (E_DEC_OVERFLOW | E_DEC_DIV_ZERO | E_DEC_BAD_NUM | E_DEC_OOM) |
#define | E_DEC_ERROR (E_DEC_FATAL_ERROR | E_DEC_TRUNCATED) |
Typedefs | |
typedef int32 | decimal_digit_t |
Enumerations | |
enum | decimal_round_mode { TRUNCATE = 0 , HALF_EVEN , HALF_UP , CEILING , FLOOR } |
Functions | |
void | widen_fraction (int new_frac, decimal_t *d) |
Add zeros behind comma to increase precision of decimal. More... | |
int | string2decimal (const char *from, decimal_t *to, const char **end) |
int | decimal2string (const decimal_t *from, char *to, int *to_len, int fixed_precision, int fixed_decimals) |
int | decimal2string (const decimal_t *from, char *to, int *to_len) |
int | decimal2ulonglong (const decimal_t *from, ulonglong *to) |
int | ulonglong2decimal (ulonglong from, decimal_t *to) |
int | decimal2longlong (const decimal_t *from, longlong *to) |
int | longlong2decimal (longlong from, decimal_t *to) |
int | decimal2double (const decimal_t *from, double *to) |
int | double2decimal (double from, decimal_t *to) |
int | decimal_actual_fraction (const decimal_t *from) |
int | decimal2bin (const decimal_t *from, uchar *to, int precision, int scale) |
int | bin2decimal (const uchar *from, decimal_t *to, int precision, int scale, bool keep_prec=false) |
int | decimal2lldiv_t (const decimal_t *from, lldiv_t *to) |
Convert decimal to lldiv_t. More... | |
int | double2lldiv_t (double nr, lldiv_t *lld) |
Convert double value to lldiv_t value. More... | |
int | decimal_size (int precision, int scale) |
int | decimal_bin_size (int precision, int scale) |
int | decimal_intg (const decimal_t *from) |
Returns the number of decimal digits before the decimal point in a decimal_t, with any insignificant leading zeros removed. More... | |
int | decimal_add (const decimal_t *from1, const decimal_t *from2, decimal_t *to) |
int | decimal_sub (const decimal_t *from1, const decimal_t *from2, decimal_t *to) |
int | decimal_cmp (const decimal_t *from1, const decimal_t *from2) |
int | decimal_mul (const decimal_t *from1, const decimal_t *from2, decimal_t *to) |
int | decimal_div (const decimal_t *from1, const decimal_t *from2, decimal_t *to, int scale_incr) |
int | decimal_mod (const decimal_t *from1, const decimal_t *from2, decimal_t *to) |
int | decimal_round (const decimal_t *from, decimal_t *to, int new_scale, decimal_round_mode mode) |
int | decimal_is_zero (const decimal_t *from) |
void | max_decimal (int precision, int frac, decimal_t *to) |
int | decimal_shift (decimal_t *dec, int shift) |
static void | decimal_make_zero (decimal_t *dec) |
static int | decimal_string_size (const decimal_t *dec) |
Returns the length of the buffer to hold string representation of the decimal (including decimal dot, possible sign and \0) More... | |
Variables | |
static constexpr int | DECIMAL_MAX_SCALE {30} |
static constexpr int | DECIMAL_NOT_SPECIFIED {DECIMAL_MAX_SCALE + 1} |
#define E_DEC_BAD_NUM 8 |
#define E_DEC_DIV_ZERO 4 |
#define E_DEC_ERROR (E_DEC_FATAL_ERROR | E_DEC_TRUNCATED) |
#define E_DEC_FATAL_ERROR (E_DEC_OVERFLOW | E_DEC_DIV_ZERO | E_DEC_BAD_NUM | E_DEC_OOM) |
#define E_DEC_OK 0 |
#define E_DEC_OOM 16 |
#define E_DEC_OVERFLOW 2 |
#define E_DEC_TRUNCATED 1 |
typedef int32 decimal_digit_t |
enum decimal_round_mode |
int bin2decimal | ( | const uchar * | from, |
decimal_t * | to, | ||
int | precision, | ||
int | scale, | ||
bool | keep_prec = false |
||
) |
int decimal2double | ( | const decimal_t * | from, |
double * | to | ||
) |
int decimal2lldiv_t | ( | const decimal_t * | from, |
lldiv_t * | to | ||
) |
Convert decimal to lldiv_t.
The integer part is stored in to->quot. The fractional part is multiplied to 10^9 and stored to to->rem.
from | Decimal value | |
[out] | to | lldiv_t value |
0 | on success |
!0 | in error |
|
inline |
int decimal2string | ( | const decimal_t * | from, |
char * | to, | ||
int * | to_len, | ||
int | fixed_precision, | ||
int | fixed_decimals | ||
) |
int decimal_actual_fraction | ( | const decimal_t * | from | ) |
int decimal_bin_size | ( | int | precision, |
int | scale | ||
) |
int decimal_div | ( | const decimal_t * | from1, |
const decimal_t * | from2, | ||
decimal_t * | to, | ||
int | scale_incr | ||
) |
int decimal_intg | ( | const decimal_t * | from | ) |
Returns the number of decimal digits before the decimal point in a decimal_t, with any insignificant leading zeros removed.
int decimal_is_zero | ( | const decimal_t * | from | ) |
|
inlinestatic |
int decimal_round | ( | const decimal_t * | from, |
decimal_t * | to, | ||
int | new_scale, | ||
decimal_round_mode | mode | ||
) |
int decimal_shift | ( | decimal_t * | dec, |
int | shift | ||
) |
int decimal_size | ( | int | precision, |
int | scale | ||
) |
|
inlinestatic |
Returns the length of the buffer to hold string representation of the decimal (including decimal dot, possible sign and \0)
int double2decimal | ( | double | from, |
decimal_t * | to | ||
) |
int double2lldiv_t | ( | double | nr, |
lldiv_t * | lld | ||
) |
Convert double value to lldiv_t value.
nr | The double value to convert from. | |
[out] | lld | The lldit_t variable to convert to. |
Integer part goes into lld.quot. Fractional part multiplied to 1000000000 (10^9) goes to lld.rem. Typically used in datetime calculations to split seconds and nanoseconds.
void max_decimal | ( | int | precision, |
int | frac, | ||
decimal_t * | to | ||
) |
int string2decimal | ( | const char * | from, |
decimal_t * | to, | ||
const char ** | end | ||
) |
void widen_fraction | ( | int | new_frac, |
decimal_t * | d | ||
) |
Add zeros behind comma to increase precision of decimal.
new_frac | the new fraction | |
[in,out] | d | the decimal target |
new_frac is expected to >= than cd->frac and new fraction is expected to fit in d.
|
staticconstexpr |
|
staticconstexpr |