24#ifndef MY_DECIMAL_INCLUDED
25#define MY_DECIMAL_INCLUDED
97 std::array<decimal_digit_t, DECIMAL_BUFF_LENGTH>
buffer;
108 if (
this == &rhs)
return *
this;
109 decimal_t::operator=(rhs);
149#define dbug_decimal_as_string(A) NULL
166 const bool sign = val->
sign();
181 bool unsigned_flag) {
185 (uint)(
length - (scale > 0 ? 1 : 0) - (unsigned_flag || !
length ? 0 : 1));
191 bool unsigned_flag) {
196 assert(precision || !scale);
197 const uint32 retval = (
uint32)(precision + (scale > 0 ? 1 : 0) +
198 (unsigned_flag || !precision ? 0 : 1));
199 if (retval == 0)
return 1;
204 bool unsigned_flag) {
209 assert(precision || !scale);
232 int prec,
int scale) {
251 int prec,
int scale,
bool keep_prec) {
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:96
int check_result(uint, int result) const
report result of decimal operation.
Definition: my_decimal.cc:61
void sign(bool s)
Definition: my_decimal.h:130
my_decimal()
Definition: my_decimal.h:121
void init()
Definition: my_decimal.h:115
my_decimal & operator=(const my_decimal &rhs)
Definition: my_decimal.h:105
void sanity_check() const
Definition: my_decimal.h:127
my_decimal(const my_decimal &rhs)
Definition: my_decimal.h:100
uint precision() const
Definition: my_decimal.h:131
~my_decimal()
Definition: my_decimal.h:124
bool sign() const
Definition: my_decimal.h:129
void swap(my_decimal &rhs)
Swap two my_decimal values.
Definition: my_decimal.h:134
std::array< decimal_digit_t, DECIMAL_BUFF_LENGTH > buffer
Definition: my_decimal.h:97
int decimal_round(const decimal_t *from, decimal_t *to, int new_scale, decimal_round_mode mode)
Definition: decimal.cc:1653
int decimal_bin_size(int precision, int scale)
Definition: decimal.cc:1631
int decimal2longlong(const decimal_t *from, longlong *to)
Definition: decimal.cc:1175
int ulonglong2decimal(ulonglong from, decimal_t *to)
Definition: decimal.cc:1139
int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2083
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,...
Definition: decimal.h:135
int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale, bool keep_prec=false)
Definition: decimal.cc:1486
int decimal_mod(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2510
@ CEILING
Definition: decimal.h:38
@ FLOOR
Definition: decimal.h:39
@ HALF_UP
Definition: decimal.h:37
@ TRUNCATE
Definition: decimal.h:35
int decimal_add(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2034
int decimal_is_zero(const decimal_t *from)
Definition: decimal.cc:2054
#define E_DEC_DIV_ZERO
Definition: decimal.h:151
int longlong2decimal(longlong from, decimal_t *to)
Definition: decimal.cc:1144
int decimal2lldiv_t(const decimal_t *from, lldiv_t *to)
Convert decimal to lldiv_t.
Definition: decimal.cc:1222
void max_decimal(int precision, int frac, decimal_t *to)
Definition: decimal.cc:432
int decimal2ulonglong(const decimal_t *from, ulonglong *to)
Definition: decimal.cc:1151
int decimal_div(const decimal_t *from1, const decimal_t *from2, decimal_t *to, int scale_incr)
Definition: decimal.cc:2478
int string2decimal(const char *from, decimal_t *to, const char **end)
Definition: decimal.cc:932
static void decimal_make_zero(decimal_t *dec)
Definition: decimal.h:124
int decimal2double(const decimal_t *from, double *to)
Definition: decimal.cc:1075
int decimal_cmp(const decimal_t *from1, const decimal_t *from2)
Definition: decimal.cc:2044
int decimal_intg(const decimal_t *from)
Returns the number of decimal digits before the decimal point in a decimal_t, with any insignificant ...
Definition: decimal.cc:2028
int double2decimal(double from, decimal_t *to)
Definition: decimal.cc:1100
int decimal_sub(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2039
#define E_DEC_OVERFLOW
Definition: decimal.h:150
static constexpr int DECIMAL_NOT_SPECIFIED
Definition: dtoa.h:54
static constexpr int DECIMAL_MAX_SCALE
Definition: dtoa.h:53
static const std::string dec("DECRYPTION")
A better implementation of the UNIX ctype(3) library.
static mi_bit_type mask[]
Definition: mi_packrec.cc:141
int my_decimal_int_part(uint precision, uint decimals)
Definition: my_decimal.h:84
int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec, int scale)
Definition: my_decimal.cc:223
void max_internal_decimal(my_decimal *to)
Definition: my_decimal.h:160
int check_result_and_overflow(uint mask, int result, my_decimal *val)
Definition: my_decimal.h:164
int my_decimal_sub(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:347
int int2my_decimal(uint mask, longlong i, bool unsigned_flag, my_decimal *d)
Definition: my_decimal.h:326
void print_decimal_buff(const my_decimal *dec, const uchar *ptr, int length)
Definition: my_decimal.cc:370
my_decimal * timeval2my_decimal(const my_timeval *tm, my_decimal *dec)
Convert timeval value to my_decimal.
Definition: my_decimal.cc:335
int double2my_decimal(uint mask, double val, my_decimal *d)
Definition: my_decimal.h:322
bool operator!=(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:381
void max_my_decimal(my_decimal *to, int precision, int frac)
Definition: my_decimal.h:155
int my_decimal2string(uint mask, const my_decimal *d, uint fixed_prec, uint fixed_dec, String *str)
Converting decimal to string.
Definition: my_decimal.cc:126
static constexpr int DECIMAL_MAX_FIELD_SIZE
maximum size of packet length.
Definition: my_decimal.h:82
int my_decimal_get_binary_size(uint precision, uint scale)
Definition: my_decimal.h:220
static constexpr int DECIMAL_LONGLONG_DIGITS
Definition: my_decimal.h:56
int my_decimal2lldiv_t(uint mask, const my_decimal *d, lldiv_t *to)
Definition: my_decimal.h:306
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.
Definition: my_decimal.cc:172
int my_decimal_add(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:342
static constexpr int DECIMAL_BUFF_LENGTH
maximum length of buffer in our big digits (uint32).
Definition: my_decimal.h:59
int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:363
void my_decimal_neg(decimal_t *arg)
Definition: my_decimal.h:333
int my_decimal_floor(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:275
int my_decimal2double(uint, const my_decimal *d, double *result)
Definition: my_decimal.h:301
bool my_decimal_is_zero(const my_decimal *decimal_value)
Definition: my_decimal.h:265
void print_decimal(const my_decimal *dec)
Definition: my_decimal.cc:357
uint my_decimal_length_to_precision(uint length, uint scale, bool unsigned_flag)
Definition: my_decimal.h:180
int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d, int prec, int scale)
Definition: my_decimal.h:231
uint32 my_decimal_precision_to_length(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:203
void my_decimal_trim(ulong *precision, uint *scale)
Definition: my_decimal.cc:342
int my_decimal_cmp(const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:373
my_decimal * date2my_decimal(const MYSQL_TIME *ltime, my_decimal *dec)
Convert datetime value to my_decimal in format YYYYMMDDhhmmss.ffffff.
Definition: my_decimal.cc:311
bool operator<(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:377
int my_decimal_intg(const my_decimal *a)
Definition: my_decimal.h:385
int my_decimal_set_zero(my_decimal *d)
Definition: my_decimal.h:255
int my_decimal_div(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b, int div_scale_inc)
Definition: my_decimal.h:357
int my_decimal_round(uint mask, const my_decimal *from, int scale, bool truncate, my_decimal *to)
Definition: my_decimal.h:269
my_decimal * time2my_decimal(const MYSQL_TIME *ltime, my_decimal *dec)
Convert time value to my_decimal in format hhmmss.ffffff.
Definition: my_decimal.cc:325
void my_decimal2decimal(const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:224
static constexpr int DECIMAL_MAX_PRECISION
maximum guaranteed precision of number in decimal digits (number of our digits * number of decimal di...
Definition: my_decimal.h:70
int my_decimal2int(uint mask, const my_decimal *d, bool unsigned_flag, longlong *l)
Definition: my_decimal.h:291
static constexpr int DECIMAL_MAX_STR_LENGTH
maximum length of string representation (number of maximum decimal digits + 1 position for sign + 1 p...
Definition: my_decimal.h:77
int my_decimal_string_length(const my_decimal *d)
Definition: my_decimal.h:215
int my_decimal_ceiling(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:279
static constexpr int DECIMAL_MAX_POSSIBLE_PRECISION
the number of digits that my_decimal can possibly contain
Definition: my_decimal.h:62
int my_decimal_mul(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:352
int str2my_decimal(uint mask, const char *str, my_decimal *d, const char **end)
Definition: my_decimal.h:310
const char * dbug_decimal_as_string(char *buff, const my_decimal *val)
Definition: my_decimal.cc:379
uint32 my_decimal_precision_to_length_no_truncation(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:189
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint8_t uint8
Definition: my_inttypes.h:63
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
uint32_t uint32
Definition: my_inttypes.h:67
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
Definition: buf0block_hint.cc:30
const std::string charset("charset")
Definition: commit_order_queue.h:34
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
struct result result
Definition: result.h:34
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:663
Definition: m_ctype.h:421
Definition: mysql_time.h:82
Base struct used to represent decimal data type.
Definition: decimal.h:49
int frac
The number of decimal digits after the point.
Definition: decimal.h:54
int intg
The number of decimal digits (NOT number of decimal_digit_t's !) before the point.
Definition: decimal.h:52
bool sign
False means positive, true means negative.
Definition: decimal.h:59
int len
The length of buf (length of allocated space) in decimal_digit_t's, not in bytes.
Definition: decimal.h:57
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:45