24#ifndef MY_DECIMAL_INCLUDED
25#define MY_DECIMAL_INCLUDED
126 if (
this == &rhs)
return *
this;
127 decimal_t::operator=(rhs);
178#define dbug_decimal_as_string(A) NULL
197 bool sign = val->
sign();
212 bool unsigned_flag) {
222 bool unsigned_flag) {
227 assert(precision || !scale);
228 uint32 retval = (
uint32)(precision + (scale > 0 ? 1 : 0) +
229 (unsigned_flag || !precision ? 0 : 1));
230 if (retval == 0)
return 1;
235 bool unsigned_flag) {
240 assert(precision || !scale);
263 int prec,
int scale) {
282 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:168
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:94
int check_result(uint, int result) const
report result of decimal operation.
Definition: my_decimal.cc:56
int foo2
Definition: my_decimal.h:108
void sign(bool s)
Definition: my_decimal.h:159
decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]
Definition: my_decimal.h:105
static const int test_value
Definition: my_decimal.h:109
my_decimal()
Definition: my_decimal.h:146
void init()
Definition: my_decimal.h:133
my_decimal & operator=(const my_decimal &rhs)
Definition: my_decimal.h:123
void sanity_check() const
Definition: my_decimal.h:152
int foo1
Definition: my_decimal.h:102
my_decimal(const my_decimal &rhs)
Definition: my_decimal.h:113
uint precision() const
Definition: my_decimal.h:160
~my_decimal()
Definition: my_decimal.h:149
bool sign() const
Definition: my_decimal.h:158
void swap(my_decimal &rhs)
Swap two my_decimal values.
Definition: my_decimal.h:163
int decimal_round(const decimal_t *from, decimal_t *to, int new_scale, decimal_round_mode mode)
Definition: decimal.cc:1657
int decimal_bin_size(int precision, int scale)
Definition: decimal.cc:1635
int decimal2longlong(const decimal_t *from, longlong *to)
Definition: decimal.cc:1178
int ulonglong2decimal(ulonglong from, decimal_t *to)
Definition: decimal.cc:1142
int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2087
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:129
int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale, bool keep_prec=false)
Definition: decimal.cc:1489
int decimal_mod(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2513
@ 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:2038
int decimal_is_zero(const decimal_t *from)
Definition: decimal.cc:2058
#define E_DEC_DIV_ZERO
Definition: decimal.h:145
int longlong2decimal(longlong from, decimal_t *to)
Definition: decimal.cc:1147
int decimal2lldiv_t(const decimal_t *from, lldiv_t *to)
Convert decimal to lldiv_t.
Definition: decimal.cc:1225
static constexpr int DECIMAL_NOT_SPECIFIED
Definition: decimal.h:154
void max_decimal(int precision, int frac, decimal_t *to)
Definition: decimal.cc:429
int32 decimal_digit_t
Definition: decimal.h:41
int decimal2ulonglong(const decimal_t *from, ulonglong *to)
Definition: decimal.cc:1154
int decimal_div(const decimal_t *from1, const decimal_t *from2, decimal_t *to, int scale_incr)
Definition: decimal.cc:2481
int string2decimal(const char *from, decimal_t *to, const char **end)
Definition: decimal.cc:929
static void decimal_make_zero(decimal_t *dec)
Definition: decimal.h:118
int decimal2double(const decimal_t *from, double *to)
Definition: decimal.cc:1072
int decimal_cmp(const decimal_t *from1, const decimal_t *from2)
Definition: decimal.cc:2048
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:2032
int double2decimal(double from, decimal_t *to)
Definition: decimal.cc:1101
int decimal_sub(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2043
#define E_DEC_OVERFLOW
Definition: decimal.h:144
static constexpr int DECIMAL_MAX_SCALE
Definition: decimal.h:153
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:82
int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec, int scale)
Definition: my_decimal.cc:216
void max_internal_decimal(my_decimal *to)
Definition: my_decimal.h:191
int check_result_and_overflow(uint mask, int result, my_decimal *val)
Definition: my_decimal.h:195
int my_decimal_sub(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:378
int int2my_decimal(uint mask, longlong i, bool unsigned_flag, my_decimal *d)
Definition: my_decimal.h:357
void print_decimal_buff(const my_decimal *dec, const uchar *ptr, int length)
Definition: my_decimal.cc:363
my_decimal * timeval2my_decimal(const my_timeval *tm, my_decimal *dec)
Convert timeval value to my_decimal.
Definition: my_decimal.cc:328
int double2my_decimal(uint mask, double val, my_decimal *d)
Definition: my_decimal.h:353
bool operator!=(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:412
void max_my_decimal(my_decimal *to, int precision, int frac)
Definition: my_decimal.h:186
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:119
static constexpr int DECIMAL_MAX_FIELD_SIZE
maximum size of packet length.
Definition: my_decimal.h:80
int my_decimal_get_binary_size(uint precision, uint scale)
Definition: my_decimal.h:251
static constexpr int DECIMAL_LONGLONG_DIGITS
Definition: my_decimal.h:54
int my_decimal2lldiv_t(uint mask, const my_decimal *d, lldiv_t *to)
Definition: my_decimal.h:337
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:165
int my_decimal_add(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:373
static constexpr int DECIMAL_BUFF_LENGTH
maximum length of buffer in our big digits (uint32).
Definition: my_decimal.h:57
int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:394
void my_decimal_neg(decimal_t *arg)
Definition: my_decimal.h:364
int my_decimal_floor(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:306
int my_decimal2double(uint, const my_decimal *d, double *result)
Definition: my_decimal.h:332
bool my_decimal_is_zero(const my_decimal *decimal_value)
Definition: my_decimal.h:296
void print_decimal(const my_decimal *dec)
Definition: my_decimal.cc:350
uint my_decimal_length_to_precision(uint length, uint scale, bool unsigned_flag)
Definition: my_decimal.h:211
int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d, int prec, int scale)
Definition: my_decimal.h:262
uint32 my_decimal_precision_to_length(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:234
void my_decimal_trim(ulong *precision, uint *scale)
Definition: my_decimal.cc:335
int my_decimal_cmp(const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:404
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:304
bool operator<(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:408
int my_decimal_intg(const my_decimal *a)
Definition: my_decimal.h:416
int my_decimal_set_zero(my_decimal *d)
Definition: my_decimal.h:286
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:388
int my_decimal_round(uint mask, const my_decimal *from, int scale, bool truncate, my_decimal *to)
Definition: my_decimal.h:300
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:318
void my_decimal2decimal(const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:255
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:68
int my_decimal2int(uint mask, const my_decimal *d, bool unsigned_flag, longlong *l)
Definition: my_decimal.h:322
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:75
int my_decimal_string_length(const my_decimal *d)
Definition: my_decimal.h:246
int my_decimal_ceiling(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:310
static constexpr int DECIMAL_MAX_POSSIBLE_PRECISION
the number of digits that my_decimal can possibly contain
Definition: my_decimal.h:60
int my_decimal_mul(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:383
int str2my_decimal(uint mask, const char *str, my_decimal *d, const char **end)
Definition: my_decimal.h:341
const char * dbug_decimal_as_string(char *buff, const my_decimal *val)
Definition: my_decimal.cc:372
uint32 my_decimal_precision_to_length_no_truncation(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:220
my_decimal decimal_zero
Definition: mysqld.cc:1518
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:1052
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:642
Definition: m_ctype.h:385
Definition: mysql_time.h:82
intg is the number of decimal digits (NOT number of decimal_digit_t's !) before the point frac is the...
Definition: decimal.h:52
int frac
Definition: decimal.h:53
int intg
Definition: decimal.h:53
bool sign
Definition: decimal.h:54
int len
Definition: decimal.h:53
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
unsigned int uint
Definition: uca9-dump.cc:75