24#ifndef MY_DECIMAL_INCLUDED
25#define MY_DECIMAL_INCLUDED
127 if (
this == &rhs)
return *
this;
128 decimal_t::operator=(rhs);
179#define dbug_decimal_as_string(A) NULL
198 const bool sign = val->
sign();
213 bool unsigned_flag) {
217 (uint)(
length - (scale > 0 ? 1 : 0) - (unsigned_flag || !
length ? 0 : 1));
223 bool unsigned_flag) {
228 assert(precision || !scale);
229 const uint32 retval = (
uint32)(precision + (scale > 0 ? 1 : 0) +
230 (unsigned_flag || !precision ? 0 : 1));
231 if (retval == 0)
return 1;
236 bool unsigned_flag) {
241 assert(precision || !scale);
264 int prec,
int scale) {
283 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:95
int check_result(uint, int result) const
report result of decimal operation.
Definition: my_decimal.cc:61
int foo2
Definition: my_decimal.h:109
void sign(bool s)
Definition: my_decimal.h:160
decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]
Definition: my_decimal.h:106
static const int test_value
Definition: my_decimal.h:110
my_decimal()
Definition: my_decimal.h:147
void init()
Definition: my_decimal.h:134
my_decimal & operator=(const my_decimal &rhs)
Definition: my_decimal.h:124
void sanity_check() const
Definition: my_decimal.h:153
int foo1
Definition: my_decimal.h:103
my_decimal(const my_decimal &rhs)
Definition: my_decimal.h:114
uint precision() const
Definition: my_decimal.h:161
~my_decimal()
Definition: my_decimal.h:150
bool sign() const
Definition: my_decimal.h:159
void swap(my_decimal &rhs)
Swap two my_decimal values.
Definition: my_decimal.h:164
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:129
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:145
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
int32 decimal_digit_t
Definition: decimal.h:41
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:118
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:144
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:83
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:192
int check_result_and_overflow(uint mask, int result, my_decimal *val)
Definition: my_decimal.h:196
int my_decimal_sub(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:379
int int2my_decimal(uint mask, longlong i, bool unsigned_flag, my_decimal *d)
Definition: my_decimal.h:358
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:354
bool operator!=(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:413
void max_my_decimal(my_decimal *to, int precision, int frac)
Definition: my_decimal.h:187
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:81
int my_decimal_get_binary_size(uint precision, uint scale)
Definition: my_decimal.h:252
static constexpr int DECIMAL_LONGLONG_DIGITS
Definition: my_decimal.h:55
int my_decimal2lldiv_t(uint mask, const my_decimal *d, lldiv_t *to)
Definition: my_decimal.h:338
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:374
static constexpr int DECIMAL_BUFF_LENGTH
maximum length of buffer in our big digits (uint32).
Definition: my_decimal.h:58
int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:395
void my_decimal_neg(decimal_t *arg)
Definition: my_decimal.h:365
int my_decimal_floor(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:307
int my_decimal2double(uint, const my_decimal *d, double *result)
Definition: my_decimal.h:333
bool my_decimal_is_zero(const my_decimal *decimal_value)
Definition: my_decimal.h:297
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:212
int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d, int prec, int scale)
Definition: my_decimal.h:263
uint32 my_decimal_precision_to_length(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:235
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:405
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:409
int my_decimal_intg(const my_decimal *a)
Definition: my_decimal.h:417
int my_decimal_set_zero(my_decimal *d)
Definition: my_decimal.h:287
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:389
int my_decimal_round(uint mask, const my_decimal *from, int scale, bool truncate, my_decimal *to)
Definition: my_decimal.h:301
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:256
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:69
int my_decimal2int(uint mask, const my_decimal *d, bool unsigned_flag, longlong *l)
Definition: my_decimal.h:323
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:76
int my_decimal_string_length(const my_decimal *d)
Definition: my_decimal.h:247
int my_decimal_ceiling(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:311
static constexpr int DECIMAL_MAX_POSSIBLE_PRECISION
the number of digits that my_decimal can possibly contain
Definition: my_decimal.h:61
int my_decimal_mul(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:384
int str2my_decimal(uint mask, const char *str, my_decimal *d, const char **end)
Definition: my_decimal.h:342
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:221
my_decimal decimal_zero
Definition: mysqld.cc:1514
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:1081
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:423
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