MySQL  8.0.19
Source Code Documentation
my_decimal.h
Go to the documentation of this file.
1 /* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef MY_DECIMAL_INCLUDED
24 #define MY_DECIMAL_INCLUDED
25 
26 /**
27  @file
28 
29  It is interface module to fixed precision decimals library.
30 
31  Most functions use 'uint mask' as parameter, if during operation error
32  which fit in this mask is detected then it will be processed automatically
33  here. (errors are E_DEC_* constants, see include/decimal.h)
34 
35  Most function are just inline wrappers around library calls
36 */
37 
38 #include <stdlib.h>
39 #include <sys/types.h>
40 #include <algorithm>
41 
42 #include "decimal.h"
43 #include "m_ctype.h"
44 #include "my_dbug.h"
45 #include "my_inttypes.h"
46 #include "my_macros.h"
47 
48 class String;
49 struct MYSQL_TIME;
50 
51 static constexpr int DECIMAL_LONGLONG_DIGITS{22};
52 
53 /** maximum length of buffer in our big digits (uint32). */
54 static constexpr int DECIMAL_BUFF_LENGTH{9};
55 
56 /** the number of digits that my_decimal can possibly contain */
58 
59 /**
60  maximum guaranteed precision of number in decimal digits (number of our
61  digits * number of decimal digits in one our big digit - number of decimal
62  digits in one our big digit decreased by 1 (because we always put decimal
63  point on the border of our big digits))
64 */
66  8 * 2};
67 
68 /**
69  maximum length of string representation (number of maximum decimal
70  digits + 1 position for sign + 1 position for decimal point, no terminator)
71 */
73 
74 /**
75  maximum size of packet length.
76 */
78 
79 inline int my_decimal_int_part(uint precision, uint decimals) {
80  return precision - ((decimals == DECIMAL_NOT_SPECIFIED) ? 0 : decimals);
81 }
82 
83 /**
84  my_decimal class limits 'decimal_t' type to what we need in MySQL.
85 
86  It contains internally all necessary space needed by the instance so
87  no extra memory is needed. Objects should be moved using copy CTOR
88  or assignment operator, rather than memcpy/memmove.
89 */
90 
91 class my_decimal : public decimal_t {
92 /*
93  Several of the routines in strings/decimal.c have had buffer
94  overrun/underrun problems. These are *not* caught by valgrind.
95  To catch them, we allocate dummy fields around the buffer,
96  and test that their values do not change.
97  */
98 #if !defined(DBUG_OFF)
99  int foo1;
100 #endif
101 
103 
104 #if !defined(DBUG_OFF)
105  int foo2;
106  static const int test_value = 123;
107 #endif
108 
109  public:
110  my_decimal(const my_decimal &rhs) : decimal_t(rhs) {
111  rhs.sanity_check();
112 #if !defined(DBUG_OFF)
113  foo1 = test_value;
114  foo2 = test_value;
115 #endif
116  for (uint i = 0; i < DECIMAL_BUFF_LENGTH; i++) buffer[i] = rhs.buffer[i];
117  buf = buffer;
118  }
119 
121  sanity_check();
122  rhs.sanity_check();
123  if (this == &rhs) return *this;
124  decimal_t::operator=(rhs);
125  for (uint i = 0; i < DECIMAL_BUFF_LENGTH; i++) buffer[i] = rhs.buffer[i];
126  buf = buffer;
127  return *this;
128  }
129 
130  void init() {
131 #if !defined(DBUG_OFF)
132  foo1 = test_value;
133  foo2 = test_value;
134 #endif
135  /*
136  Do not initialize more of the base class,
137  we want to catch uninitialized use.
138  */
140  buf = buffer;
141  }
142 
143  my_decimal() { init(); }
144 
145 #ifndef DBUG_OFF
147 #endif // DBUG_OFF
148 
149  void sanity_check() const {
152  DBUG_ASSERT(buf == buffer);
153  }
154 
155  bool sign() const { return decimal_t::sign; }
156  void sign(bool s) { decimal_t::sign = s; }
157  uint precision() const { return intg + frac; }
158 
159  /** Swap two my_decimal values */
160  void swap(my_decimal &rhs) { std::swap(*this, rhs); }
161 
162 #ifndef MYSQL_SERVER
163  // Error reporting in server code only.
164  int check_result(uint, int result) const { return result; }
165 #else
166  int check_result(uint, int result) const;
167 #endif
168 };
169 
170 #ifndef DBUG_OFF
171 void print_decimal(const my_decimal *dec);
172 void print_decimal_buff(const my_decimal *dec, const uchar *ptr, int length);
173 const char *dbug_decimal_as_string(char *buff, const my_decimal *val);
174 #else
175 #define dbug_decimal_as_string(A) NULL
176 #endif
177 
178 bool str_set_decimal(uint mask, const my_decimal *val, String *str,
179  const CHARSET_INFO *cs);
180 
181 extern my_decimal decimal_zero;
182 
183 inline void max_my_decimal(my_decimal *to, int precision, int frac) {
184  DBUG_ASSERT((precision <= DECIMAL_MAX_PRECISION) &&
185  (frac <= DECIMAL_MAX_SCALE));
186  max_decimal(precision, frac, to);
187 }
188 
191 }
192 
194  if (val->check_result(mask, result) & E_DEC_OVERFLOW) {
195  bool sign = val->sign();
196  val->sanity_check();
198  val->sign(sign);
199  }
200  /*
201  Avoid returning negative zero, cfr. decimal_cmp()
202  For result == E_DEC_DIV_ZERO *val has not been assigned.
203  */
204  if (result != E_DEC_DIV_ZERO && val->sign() && decimal_is_zero(val))
205  val->sign(false);
206  return result;
207 }
208 
210  bool unsigned_flag) {
211  /* Precision can't be negative thus ignore unsigned_flag when length is 0. */
212  DBUG_ASSERT(length || !scale);
213  uint retval =
214  (uint)(length - (scale > 0 ? 1 : 0) - (unsigned_flag || !length ? 0 : 1));
215  return retval;
216 }
217 
219  uint8 scale,
220  bool unsigned_flag) {
221  /*
222  When precision is 0 it means that original length was also 0. Thus
223  unsigned_flag is ignored in this case.
224  */
225  DBUG_ASSERT(precision || !scale);
226  uint32 retval = (uint32)(precision + (scale > 0 ? 1 : 0) +
227  (unsigned_flag || !precision ? 0 : 1));
228  return retval;
229 }
230 
232  bool unsigned_flag) {
233  /*
234  When precision is 0 it means that original length was also 0. Thus
235  unsigned_flag is ignored in this case.
236  */
237  DBUG_ASSERT(precision || !scale);
238  precision = std::min(precision, uint(DECIMAL_MAX_PRECISION));
239  return my_decimal_precision_to_length_no_truncation(precision, scale,
240  unsigned_flag);
241 }
242 
243 inline int my_decimal_string_length(const my_decimal *d) {
244  /* length of string representation including terminating '\0' */
245  return decimal_string_size(d);
246 }
247 
248 inline int my_decimal_get_binary_size(uint precision, uint scale) {
249  return decimal_bin_size((int)precision, (int)scale);
250 }
251 
252 inline void my_decimal2decimal(const my_decimal *from, my_decimal *to) {
253  *to = *from;
254 }
255 
256 int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec,
257  int scale);
258 
259 inline int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d,
260  int prec, int scale) {
261  return d->check_result(mask, bin2decimal(bin, d, prec, scale, false));
262 }
263 
264 /**
265  Decode DECIMAL from binary form
266 
267  @param mask Error mask
268  @param bin Binary string to decode
269  @param d [out] DECIMAL buffer
270  @param prec Precision of stored value
271  @param scale Scale of stored value
272  @param keep_prec Whether to keep stored value's precision
273 
274  @returns
275  conversion error
276 */
277 
278 inline int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d,
279  int prec, int scale, bool keep_prec) {
280  return d->check_result(mask, bin2decimal(bin, d, prec, scale, keep_prec));
281 }
282 
284  /*
285  We need the up-cast here, since my_decimal has sign() member functions,
286  which conflicts with decimal_t::size
287  (and decimal_make_zero is a macro, rather than a funcion).
288  */
289  decimal_make_zero(static_cast<decimal_t *>(d));
290  return 0;
291 }
292 
293 inline bool my_decimal_is_zero(const my_decimal *decimal_value) {
294  return decimal_is_zero(decimal_value);
295 }
296 
297 inline int my_decimal_round(uint mask, const my_decimal *from, int scale,
298  bool truncate, my_decimal *to) {
299  return from->check_result(
300  mask, decimal_round(from, to, scale, (truncate ? TRUNCATE : HALF_UP)));
301 }
302 
303 inline int my_decimal_floor(uint mask, const my_decimal *from, my_decimal *to) {
304  return from->check_result(mask, decimal_round(from, to, 0, FLOOR));
305 }
306 
307 inline int my_decimal_ceiling(uint mask, const my_decimal *from,
308  my_decimal *to) {
309  return from->check_result(mask, decimal_round(from, to, 0, CEILING));
310 }
311 
312 int my_decimal2string(uint mask, const my_decimal *d, uint fixed_prec,
313  uint fixed_dec, String *str);
314 
315 inline int my_decimal2string(uint mask, const my_decimal *d, String *str) {
316  return my_decimal2string(mask, d, 0, 0, str);
317 }
318 
319 inline int my_decimal2int(uint mask, const my_decimal *d, bool unsigned_flag,
320  longlong *l) {
321  my_decimal rounded;
322  /* decimal_round can return only E_DEC_TRUNCATED */
323  decimal_round(d, &rounded, 0, HALF_UP);
324  return d->check_result(
325  mask, (unsigned_flag ? decimal2ulonglong(&rounded, (ulonglong *)l)
326  : decimal2longlong(&rounded, l)));
327 }
328 
329 inline int my_decimal2double(uint, const my_decimal *d, double *result) {
330  /* No need to call check_result as this will always succeed */
331  return decimal2double(d, result);
332 }
333 
334 inline int my_decimal2lldiv_t(uint mask, const my_decimal *d, lldiv_t *to) {
335  return d->check_result(mask, decimal2lldiv_t(d, to));
336 }
337 
338 inline int str2my_decimal(uint mask, const char *str, my_decimal *d,
339  const char **end) {
340  return check_result_and_overflow(mask, string2decimal(str, d, end), d);
341 }
342 
343 int str2my_decimal(uint mask, const char *from, size_t length,
344  const CHARSET_INFO *charset, my_decimal *decimal_value);
345 
346 my_decimal *date2my_decimal(const MYSQL_TIME *ltime, my_decimal *dec);
347 my_decimal *time2my_decimal(const MYSQL_TIME *ltime, my_decimal *dec);
348 my_decimal *timeval2my_decimal(const struct timeval *tm, my_decimal *dec);
349 
350 inline int double2my_decimal(uint mask, double val, my_decimal *d) {
351  return check_result_and_overflow(mask, double2decimal(val, d), d);
352 }
353 
354 inline int int2my_decimal(uint mask, longlong i, bool unsigned_flag,
355  my_decimal *d) {
356  return d->check_result(mask,
357  (unsigned_flag ? ulonglong2decimal((ulonglong)i, d)
358  : longlong2decimal(i, d)));
359 }
360 
361 inline void my_decimal_neg(decimal_t *arg) {
362  // Avoid returning negative zero, cfr. decimal_cmp()
363  if (decimal_is_zero(arg)) {
364  arg->sign = false;
365  return;
366  }
367  arg->sign ^= 1;
368 }
369 
370 inline int my_decimal_add(uint mask, my_decimal *res, const my_decimal *a,
371  const my_decimal *b) {
372  return check_result_and_overflow(mask, decimal_add(a, b, res), res);
373 }
374 
375 inline int my_decimal_sub(uint mask, my_decimal *res, const my_decimal *a,
376  const my_decimal *b) {
377  return check_result_and_overflow(mask, decimal_sub(a, b, res), res);
378 }
379 
380 inline int my_decimal_mul(uint mask, my_decimal *res, const my_decimal *a,
381  const my_decimal *b) {
382  return check_result_and_overflow(mask, decimal_mul(a, b, res), res);
383 }
384 
385 inline int my_decimal_div(uint mask, my_decimal *res, const my_decimal *a,
386  const my_decimal *b, int div_scale_inc) {
387  return check_result_and_overflow(mask, decimal_div(a, b, res, div_scale_inc),
388  res);
389 }
390 
391 inline int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a,
392  const my_decimal *b) {
393  return check_result_and_overflow(mask, decimal_mod(a, b, res), res);
394 }
395 
396 /**
397  @return
398  @retval -1 if a @< b
399  @retval 1 if a @> b
400  @retval 0 if a == b
401 */
402 inline int my_decimal_cmp(const my_decimal *a, const my_decimal *b) {
403  return decimal_cmp(a, b);
404 }
405 
406 inline bool operator<(const my_decimal &lhs, const my_decimal &rhs) {
407  return my_decimal_cmp(&lhs, &rhs) < 0;
408 }
409 
410 inline bool operator!=(const my_decimal &lhs, const my_decimal &rhs) {
411  return my_decimal_cmp(&lhs, &rhs) != 0;
412 }
413 
414 inline int my_decimal_intg(const my_decimal *a) { return decimal_intg(a); }
415 
416 void my_decimal_trim(ulong *precision, uint *scale);
417 
418 #endif // MY_DECIMAL_INCLUDED
FLOOR
@ FLOOR
Definition: decimal.h:38
decimal_t::intg
int intg
Definition: decimal.h:52
my_decimal_set_zero
int my_decimal_set_zero(my_decimal *d)
Definition: my_decimal.h:283
decimal_t::len
int len
Definition: decimal.h:52
my_decimal_div
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:385
my_decimal_string_length
int my_decimal_string_length(const my_decimal *d)
Definition: my_decimal.h:243
CEILING
@ CEILING
Definition: decimal.h:37
check_result_and_overflow
int check_result_and_overflow(uint mask, int result, my_decimal *val)
Definition: my_decimal.h:193
binary2my_decimal
int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d, int prec, int scale)
Definition: my_decimal.h:259
max_decimal
void max_decimal(int precision, int frac, decimal_t *to)
Definition: decimal.cc:402
decimal.h
TRUNCATE
@ TRUNCATE
Definition: decimal.h:34
my_decimal::init
void init()
Definition: my_decimal.h:130
E_DEC_DIV_ZERO
#define E_DEC_DIV_ZERO
Definition: decimal.h:143
decimal_t::buf
decimal_digit_t * buf
Definition: decimal.h:54
decimal_t::frac
int frac
Definition: decimal.h:52
my_decimal::test_value
static const int test_value
Definition: my_decimal.h:106
CHARSET_INFO
Definition: m_ctype.h:354
longlong2decimal
int longlong2decimal(longlong from, decimal_t *to)
Definition: decimal.cc:1117
decimal_digit_t
int32 decimal_digit_t
Definition: decimal.h:40
decimal_mul
int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2068
my_dbug.h
time2my_decimal
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:307
String
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:164
decimal2double
int decimal2double(const decimal_t *from, double *to)
Definition: decimal.cc:1042
DECIMAL_MAX_PRECISION
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:65
decimal_cmp
int decimal_cmp(const decimal_t *from1, const decimal_t *from2)
Definition: decimal.cc:2029
print_decimal
void print_decimal(const my_decimal *dec)
Definition: my_decimal.cc:339
longlong
long long int longlong
Definition: my_inttypes.h:54
decimal2longlong
int decimal2longlong(const decimal_t *from, longlong *to)
Definition: decimal.cc:1148
decimal_zero
my_decimal decimal_zero
Definition: mysqld.cc:1292
max_my_decimal
void max_my_decimal(my_decimal *to, int precision, int frac)
Definition: my_decimal.h:183
result
Definition: result.h:33
my_decimal_get_binary_size
int my_decimal_get_binary_size(uint precision, uint scale)
Definition: my_decimal.h:248
double2decimal
int double2decimal(double from, decimal_t *to)
Definition: decimal.cc:1071
DECIMAL_LONGLONG_DIGITS
static constexpr int DECIMAL_LONGLONG_DIGITS
Definition: my_decimal.h:51
decimal2lldiv_t
int decimal2lldiv_t(const decimal_t *from, lldiv_t *to)
Convert decimal to lldiv_t.
Definition: decimal.cc:1201
my_decimal_floor
int my_decimal_floor(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:303
DECIMAL_BUFF_LENGTH
static constexpr int DECIMAL_BUFF_LENGTH
maximum length of buffer in our big digits (uint32).
Definition: my_decimal.h:54
operator<
bool operator<(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:406
my_decimal_precision_to_length_no_truncation
uint32 my_decimal_precision_to_length_no_truncation(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:218
decimal_mod
int decimal_mod(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2495
my_decimal::sanity_check
void sanity_check() const
Definition: my_decimal.h:149
my_decimal::swap
void swap(my_decimal &rhs)
Swap two my_decimal values.
Definition: my_decimal.h:160
DECIMAL_NOT_SPECIFIED
static constexpr int DECIMAL_NOT_SPECIFIED
Definition: decimal.h:151
my_decimal_length_to_precision
uint my_decimal_length_to_precision(uint length, uint scale, bool unsigned_flag)
Definition: my_decimal.h:209
decimal_round
int decimal_round(const decimal_t *from, decimal_t *to, int new_scale, decimal_round_mode mode)
Definition: decimal.cc:1644
my_inttypes.h
m_ctype.h
decimal_make_zero
static void decimal_make_zero(decimal_t *dec)
Definition: decimal.h:116
HALF_UP
@ HALF_UP
Definition: decimal.h:36
print_decimal_buff
void print_decimal_buff(const my_decimal *dec, const uchar *ptr, int length)
Definition: my_decimal.cc:352
decimal_div
int decimal_div(const decimal_t *from1, const decimal_t *from2, decimal_t *to, int scale_incr)
Definition: decimal.cc:2463
uint
unsigned int uint
Definition: uca-dump.cc:29
operator!=
bool operator!=(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:410
my_decimal_add
int my_decimal_add(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:370
int2my_decimal
int int2my_decimal(uint mask, longlong i, bool unsigned_flag, my_decimal *d)
Definition: my_decimal.h:354
decimal_bin_size
int decimal_bin_size(int precision, int scale)
Definition: decimal.cc:1622
my_decimal::foo1
int foo1
Definition: my_decimal.h:99
uchar
unsigned char uchar
Definition: my_inttypes.h:51
mask
static mi_bit_type mask[]
Definition: mi_packrec.cc:138
my_decimal_neg
void my_decimal_neg(decimal_t *arg)
Definition: my_decimal.h:361
str2my_decimal
int str2my_decimal(uint mask, const char *str, my_decimal *d, const char **end)
Definition: my_decimal.h:338
rules_table_service::end
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:188
swap
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:606
decimal_add
int decimal_add(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2019
my_decimal_precision_to_length
uint32 my_decimal_precision_to_length(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:231
my_decimal::my_decimal
my_decimal(const my_decimal &rhs)
Definition: my_decimal.h:110
my_decimal::my_decimal
my_decimal()
Definition: my_decimal.h:143
my_decimal
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:91
uint32
uint32_t uint32
Definition: my_inttypes.h:66
double2my_decimal
int double2my_decimal(uint mask, double val, my_decimal *d)
Definition: my_decimal.h:350
my_decimal_int_part
int my_decimal_int_part(uint precision, uint decimals)
Definition: my_decimal.h:79
max_internal_decimal
void max_internal_decimal(my_decimal *to)
Definition: my_decimal.h:189
my_decimal_is_zero
bool my_decimal_is_zero(const my_decimal *decimal_value)
Definition: my_decimal.h:293
my_decimal::precision
uint precision() const
Definition: my_decimal.h:157
date2my_decimal
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:293
my_decimal2binary
int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec, int scale)
Definition: my_decimal.cc:205
my_decimal::~my_decimal
~my_decimal()
Definition: my_decimal.h:146
my_decimal::foo2
int foo2
Definition: my_decimal.h:105
MYSQL_TIME
Definition: mysql_time.h:81
my_decimal_trim
void my_decimal_trim(ulong *precision, uint *scale)
Definition: my_decimal.cc:324
my_decimal_sub
int my_decimal_sub(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:375
uint8
uint8_t uint8
Definition: my_inttypes.h:62
str_set_decimal
bool str_set_decimal(uint mask, const my_decimal *val, String *str, const CHARSET_INFO *cs)
Converting decimal to string with character set conversion.
Definition: my_decimal.cc:163
my_decimal2double
int my_decimal2double(uint, const my_decimal *d, double *result)
Definition: my_decimal.h:329
DBUG_ASSERT
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
my_decimal2string
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:118
decimal_sub
int decimal_sub(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2024
DECIMAL_MAX_FIELD_SIZE
static constexpr int DECIMAL_MAX_FIELD_SIZE
maximum size of packet length.
Definition: my_decimal.h:77
my_decimal::sign
bool sign() const
Definition: my_decimal.h:155
my_decimal2lldiv_t
int my_decimal2lldiv_t(uint mask, const my_decimal *d, lldiv_t *to)
Definition: my_decimal.h:334
my_decimal_ceiling
int my_decimal_ceiling(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:307
my_decimal::check_result
int check_result(uint, int result) const
report result of decimal operation.
Definition: my_decimal.cc:55
DECIMAL_MAX_POSSIBLE_PRECISION
static constexpr int DECIMAL_MAX_POSSIBLE_PRECISION
the number of digits that my_decimal can possibly contain
Definition: my_decimal.h:57
decimal_is_zero
int decimal_is_zero(const decimal_t *from)
Definition: decimal.cc:2039
DECIMAL_MAX_SCALE
static constexpr int DECIMAL_MAX_SCALE
Definition: decimal.h:150
gis::length
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:75
my_decimal_mod
int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:391
timeval2my_decimal
my_decimal * timeval2my_decimal(const struct timeval *tm, my_decimal *dec)
Convert timeval value to my_decimal.
Definition: my_decimal.cc:317
decimal_intg
int decimal_intg(const decimal_t *from)
Definition: decimal.cc:2013
ulong
unsigned long ulong
Definition: my_inttypes.h:48
ulonglong2decimal
int ulonglong2decimal(ulonglong from, decimal_t *to)
Definition: decimal.cc:1112
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
DECIMAL_MAX_STR_LENGTH
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:72
udf_ext::consts::charset
const std::string charset("charset")
my_decimal::sign
void sign(bool s)
Definition: my_decimal.h:156
dbug_decimal_as_string
const char * dbug_decimal_as_string(char *buff, const my_decimal *val)
Definition: my_decimal.cc:361
my_macros.h
decimal_t
intg is the number of decimal digits (NOT number of decimal_digit_t's !) before the point frac is the...
Definition: decimal.h:51
decimal_t::sign
bool sign
Definition: decimal.h:53
my_decimal::operator=
my_decimal & operator=(const my_decimal &rhs)
Definition: my_decimal.h:120
my_decimal2int
int my_decimal2int(uint mask, const my_decimal *d, bool unsigned_flag, longlong *l)
Definition: my_decimal.h:319
result
struct result result
Definition: result.h:37
decimal_string_size
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:127
my_decimal::buffer
decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]
Definition: my_decimal.h:102
string2decimal
int string2decimal(const char *from, decimal_t *to, const char **end)
Definition: decimal.cc:902
my_decimal_intg
int my_decimal_intg(const my_decimal *a)
Definition: my_decimal.h:414
my_decimal2decimal
void my_decimal2decimal(const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:252
E_DEC_OVERFLOW
#define E_DEC_OVERFLOW
Definition: decimal.h:142
bin2decimal
int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale, bool keep_prec=false)
Definition: decimal.cc:1476
decimal2ulonglong
int decimal2ulonglong(const decimal_t *from, ulonglong *to)
Definition: decimal.cc:1124
my_decimal_mul
int my_decimal_mul(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:380
my_decimal_round
int my_decimal_round(uint mask, const my_decimal *from, int scale, bool truncate, my_decimal *to)
Definition: my_decimal.h:297
my_decimal_cmp
int my_decimal_cmp(const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:402