MySQL 8.4.3
Source Code Documentation
|
It is interface module to fixed precision decimals library. More...
#include <assert.h>
#include <stdlib.h>
#include <sys/types.h>
#include <algorithm>
#include "decimal.h"
#include "my_inttypes.h"
#include "my_macros.h"
#include "my_time_t.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/m_ctype.h"
Go to the source code of this file.
Classes | |
class | my_decimal |
my_decimal class limits 'decimal_t' type to what we need in MySQL. More... | |
Functions | |
int | my_decimal_int_part (uint precision, uint decimals) |
void | print_decimal (const my_decimal *dec) |
void | print_decimal_buff (const my_decimal *dec, const uchar *ptr, int length) |
const char * | dbug_decimal_as_string (char *buff, const my_decimal *val) |
bool | str_set_decimal (uint mask, const my_decimal *val, String *str, const CHARSET_INFO *cs, uint decimals) |
Converting decimal to string with character set conversion. More... | |
void | max_my_decimal (my_decimal *to, int precision, int frac) |
void | max_internal_decimal (my_decimal *to) |
int | check_result_and_overflow (uint mask, int result, my_decimal *val) |
uint | my_decimal_length_to_precision (uint length, uint scale, bool unsigned_flag) |
uint32 | my_decimal_precision_to_length_no_truncation (uint precision, uint8 scale, bool unsigned_flag) |
uint32 | my_decimal_precision_to_length (uint precision, uint8 scale, bool unsigned_flag) |
int | my_decimal_string_length (const my_decimal *d) |
int | my_decimal_get_binary_size (uint precision, uint scale) |
void | my_decimal2decimal (const my_decimal *from, my_decimal *to) |
int | my_decimal2binary (uint mask, const my_decimal *d, uchar *bin, int prec, int scale) |
int | binary2my_decimal (uint mask, const uchar *bin, my_decimal *d, int prec, int scale) |
int | binary2my_decimal (uint mask, const uchar *bin, my_decimal *d, int prec, int scale, bool keep_prec) |
Decode DECIMAL from binary form. More... | |
int | my_decimal_set_zero (my_decimal *d) |
bool | my_decimal_is_zero (const my_decimal *decimal_value) |
int | my_decimal_round (uint mask, const my_decimal *from, int scale, bool truncate, my_decimal *to) |
int | my_decimal_floor (uint mask, const my_decimal *from, my_decimal *to) |
int | my_decimal_ceiling (uint mask, const my_decimal *from, my_decimal *to) |
int | my_decimal2string (uint mask, const my_decimal *d, uint fixed_prec, uint fixed_dec, String *str) |
Converting decimal to string. More... | |
int | my_decimal2string (uint mask, const my_decimal *d, String *str) |
int | my_decimal2int (uint mask, const my_decimal *d, bool unsigned_flag, longlong *l) |
int | my_decimal2double (uint, const my_decimal *d, double *result) |
int | my_decimal2lldiv_t (uint mask, const my_decimal *d, lldiv_t *to) |
int | str2my_decimal (uint mask, const char *str, my_decimal *d, const char **end) |
int | str2my_decimal (uint mask, const char *from, size_t length, const CHARSET_INFO *charset, my_decimal *decimal_value) |
my_decimal * | date2my_decimal (const MYSQL_TIME *ltime, my_decimal *dec) |
Convert datetime value to my_decimal in format YYYYMMDDhhmmss.ffffff. More... | |
my_decimal * | time2my_decimal (const MYSQL_TIME *ltime, my_decimal *dec) |
Convert time value to my_decimal in format hhmmss.ffffff. More... | |
my_decimal * | timeval2my_decimal (const my_timeval *tm, my_decimal *dec) |
Convert timeval value to my_decimal. More... | |
int | double2my_decimal (uint mask, double val, my_decimal *d) |
int | int2my_decimal (uint mask, longlong i, bool unsigned_flag, my_decimal *d) |
void | my_decimal_neg (decimal_t *arg) |
int | my_decimal_add (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b) |
int | my_decimal_sub (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b) |
int | my_decimal_mul (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b) |
int | my_decimal_div (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b, int div_scale_inc) |
int | my_decimal_mod (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b) |
int | my_decimal_cmp (const my_decimal *a, const my_decimal *b) |
bool | operator< (const my_decimal &lhs, const my_decimal &rhs) |
bool | operator!= (const my_decimal &lhs, const my_decimal &rhs) |
int | my_decimal_intg (const my_decimal *a) |
void | my_decimal_trim (ulong *precision, uint *scale) |
Variables | |
static constexpr int | DECIMAL_LONGLONG_DIGITS {22} |
static constexpr int | DECIMAL_BUFF_LENGTH {9} |
maximum length of buffer in our big digits (uint32). More... | |
static constexpr int | DECIMAL_MAX_POSSIBLE_PRECISION {DECIMAL_BUFF_LENGTH * 9} |
the number of digits that my_decimal can possibly contain More... | |
static constexpr int | DECIMAL_MAX_PRECISION |
maximum guaranteed precision of number in decimal digits (number of our digits * number of decimal digits in one our big digit - number of decimal digits in one our big digit decreased by 1 (because we always put decimal point on the border of our big digits)) More... | |
static constexpr int | DECIMAL_MAX_STR_LENGTH {DECIMAL_MAX_POSSIBLE_PRECISION + 2} |
maximum length of string representation (number of maximum decimal digits + 1 position for sign + 1 position for decimal point, no terminator) More... | |
static constexpr int | DECIMAL_MAX_FIELD_SIZE {DECIMAL_MAX_PRECISION} |
maximum size of packet length. More... | |
my_decimal | decimal_zero |
It is interface module to fixed precision decimals library.
Most functions use 'uint mask' as parameter, if during operation error which fit in this mask is detected then it will be processed automatically here. (errors are E_DEC_* constants, see include/decimal.h)
Most function are just inline wrappers around library calls
|
inline |
|
inline |
Decode DECIMAL from binary form.
mask | Error mask |
bin | Binary string to decode |
d | [out] DECIMAL buffer |
prec | Precision of stored value |
scale | Scale of stored value |
keep_prec | Whether to keep stored value's precision |
|
inline |
my_decimal * date2my_decimal | ( | const MYSQL_TIME * | ltime, |
my_decimal * | dec | ||
) |
Convert datetime value to my_decimal in format YYYYMMDDhhmmss.ffffff.
ltime | Date value to convert from. |
dec | Decimal value to convert to. |
const char * dbug_decimal_as_string | ( | char * | buff, |
const my_decimal * | val | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
int my_decimal2binary | ( | uint | mask, |
const my_decimal * | d, | ||
uchar * | bin, | ||
int | prec, | ||
int | scale | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
int my_decimal2string | ( | uint | mask, |
const my_decimal * | d, | ||
uint | fixed_prec, | ||
uint | fixed_dec, | ||
String * | str | ||
) |
Converting decimal to string.
Convert given my_decimal to String; allocate buffer as needed.
[in] | mask | what problems to warn on (mask of E_DEC_* values) |
[in] | d | the decimal to print |
[in] | fixed_prec | overall number of digits if ZEROFILL, 0 otherwise |
[in] | fixed_dec | number of decimal places (if fixed_prec != 0) |
[out] | str | where to store the resulting string |
E_DEC_OK | ok |
E_DEC_TRUNCATED | truncated |
E_DEC_OVERFLOW | overflow |
E_DEC_OOM | out-of-memory |
|
inline |
|
inline |
|
inline |
-1 | if a < b |
1 | if a > b |
0 | if a == b |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void my_decimal_trim | ( | ulong * | precision, |
uint * | scale | ||
) |
|
inline |
|
inline |
void print_decimal | ( | const my_decimal * | dec | ) |
void print_decimal_buff | ( | const my_decimal * | dec, |
const uchar * | ptr, | ||
int | length | ||
) |
int str2my_decimal | ( | uint | mask, |
const char * | from, | ||
size_t | length, | ||
const CHARSET_INFO * | charset, | ||
my_decimal * | decimal_value | ||
) |
|
inline |
bool str_set_decimal | ( | uint | mask, |
const my_decimal * | val, | ||
String * | str, | ||
const CHARSET_INFO * | cs, | ||
uint | decimals | ||
) |
Converting decimal to string with character set conversion.
Convert given my_decimal to String; allocate buffer as needed.
[in] | mask | what problems to warn on (mask of E_DEC_* values) |
[in] | val | the decimal to print |
[out] | str | where to store the resulting string |
[in] | cs | character set |
[in] | decimals | round to desired number of decimals |
E_DEC_OK | ok |
E_DEC_TRUNCATED | truncated |
E_DEC_OVERFLOW | overflow |
E_DEC_OOM | out-of-memory |
Would be great to make it a method of the String class, but this would need to include my_decimal.h from sql_string.h and sql_string.cc, which is not desirable.
my_decimal * time2my_decimal | ( | const MYSQL_TIME * | ltime, |
my_decimal * | dec | ||
) |
Convert time value to my_decimal in format hhmmss.ffffff.
ltime | Date value to convert from. |
dec | Decimal value to convert to. |
my_decimal * timeval2my_decimal | ( | const my_timeval * | tm, |
my_decimal * | dec | ||
) |
Convert timeval value to my_decimal.
|
staticconstexpr |
maximum length of buffer in our big digits (uint32).
|
staticconstexpr |
|
staticconstexpr |
maximum size of packet length.
|
staticconstexpr |
the number of digits that my_decimal can possibly contain
|
staticconstexpr |
maximum guaranteed precision of number in decimal digits (number of our digits * number of decimal digits in one our big digit - number of decimal digits in one our big digit decreased by 1 (because we always put decimal point on the border of our big digits))
|
staticconstexpr |
maximum length of string representation (number of maximum decimal digits + 1 position for sign + 1 position for decimal point, no terminator)
|
extern |