MySQL  8.0.17
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 #include "sql_string.h" /* String */
48 
49 struct MYSQL_TIME;
50 
51 #define DECIMAL_LONGLONG_DIGITS 22
52 
53 /** maximum length of buffer in our big digits (uint32). */
54 #define DECIMAL_BUFF_LENGTH 9
55 
56 /* the number of digits that my_decimal can possibly contain */
57 #define DECIMAL_MAX_POSSIBLE_PRECISION (DECIMAL_BUFF_LENGTH * 9)
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 */
65 #define DECIMAL_MAX_PRECISION (DECIMAL_MAX_POSSIBLE_PRECISION - 8 * 2)
66 #define DECIMAL_MAX_SCALE 30
67 #define DECIMAL_NOT_SPECIFIED 31
68 
69 /**
70  maximum length of string representation (number of maximum decimal
71  digits + 1 position for sign + 1 position for decimal point, no terminator)
72 */
73 #define DECIMAL_MAX_STR_LENGTH (DECIMAL_MAX_POSSIBLE_PRECISION + 2)
74 
75 /**
76  maximum size of packet length.
77 */
78 #define DECIMAL_MAX_FIELD_SIZE DECIMAL_MAX_PRECISION
79 
80 inline uint my_decimal_size(uint precision, uint scale) {
81  /*
82  Always allocate more space to allow library to put decimal point
83  where it want
84  */
85  return decimal_size(precision, scale) + 1;
86 }
87 
88 inline int my_decimal_int_part(uint precision, uint decimals) {
89  return precision - ((decimals == DECIMAL_NOT_SPECIFIED) ? 0 : decimals);
90 }
91 
92 /**
93  my_decimal class limits 'decimal_t' type to what we need in MySQL.
94 
95  It contains internally all necessary space needed by the instance so
96  no extra memory is needed. Objects should be moved using copy CTOR
97  or assignment operator, rather than memcpy/memmove.
98 */
99 
100 class my_decimal : public decimal_t {
101 /*
102  Several of the routines in strings/decimal.c have had buffer
103  overrun/underrun problems. These are *not* caught by valgrind.
104  To catch them, we allocate dummy fields around the buffer,
105  and test that their values do not change.
106  */
107 #if !defined(DBUG_OFF)
108  int foo1;
109 #endif
110 
112 
113 #if !defined(DBUG_OFF)
114  int foo2;
115  static const int test_value = 123;
116 #endif
117 
118  public:
119  my_decimal(const my_decimal &rhs) : decimal_t(rhs) {
120  rhs.sanity_check();
121 #if !defined(DBUG_OFF)
122  foo1 = test_value;
123  foo2 = test_value;
124 #endif
125  for (uint i = 0; i < DECIMAL_BUFF_LENGTH; i++) buffer[i] = rhs.buffer[i];
126  buf = buffer;
127  }
128 
130  sanity_check();
131  rhs.sanity_check();
132  if (this == &rhs) return *this;
133  decimal_t::operator=(rhs);
134  for (uint i = 0; i < DECIMAL_BUFF_LENGTH; i++) buffer[i] = rhs.buffer[i];
135  buf = buffer;
136  return *this;
137  }
138 
139  void init() {
140 #if !defined(DBUG_OFF)
141  foo1 = test_value;
142  foo2 = test_value;
143 #endif
144  /*
145  Do not initialize more of the base class,
146  we want to catch uninitialized use.
147  */
149  buf = buffer;
150  }
151 
152  my_decimal() { init(); }
153 
154 #ifndef DBUG_OFF
156 #endif // DBUG_OFF
157 
158  void sanity_check() const {
161  DBUG_ASSERT(buf == buffer);
162  }
163 
164  bool sign() const { return decimal_t::sign; }
165  void sign(bool s) { decimal_t::sign = s; }
166  uint precision() const { return intg + frac; }
167 
168  /** Swap two my_decimal values */
169  void swap(my_decimal &rhs) { std::swap(*this, rhs); }
170 
171 #ifndef MYSQL_SERVER
172  // Error reporting in server code only.
173  int check_result(uint, int result) const { return result; }
174 #else
175  int check_result(uint, int result) const;
176 #endif
177 };
178 
179 #ifndef DBUG_OFF
180 void print_decimal(const my_decimal *dec);
181 void print_decimal_buff(const my_decimal *dec, const uchar *ptr, int length);
182 const char *dbug_decimal_as_string(char *buff, const my_decimal *val);
183 #else
184 #define dbug_decimal_as_string(A) NULL
185 #endif
186 
187 bool str_set_decimal(uint mask, const my_decimal *val, uint fixed_prec,
188  uint fixed_dec, char filler, String *str,
189  const CHARSET_INFO *cs);
190 
191 extern my_decimal decimal_zero;
192 
193 inline void max_my_decimal(my_decimal *to, int precision, int frac) {
194  DBUG_ASSERT((precision <= DECIMAL_MAX_PRECISION) &&
195  (frac <= DECIMAL_MAX_SCALE));
196  max_decimal(precision, frac, to);
197 }
198 
201 }
202 
203 inline int check_result_and_overflow(uint mask, int result, my_decimal *val) {
204  if (val->check_result(mask, result) & E_DEC_OVERFLOW) {
205  bool sign = val->sign();
206  val->sanity_check();
208  val->sign(sign);
209  }
210  /*
211  Avoid returning negative zero, cfr. decimal_cmp()
212  For result == E_DEC_DIV_ZERO *val has not been assigned.
213  */
214  if (result != E_DEC_DIV_ZERO && val->sign() && decimal_is_zero(val))
215  val->sign(false);
216  return result;
217 }
218 
220  bool unsigned_flag) {
221  /* Precision can't be negative thus ignore unsigned_flag when length is 0. */
222  DBUG_ASSERT(length || !scale);
223  uint retval =
224  (uint)(length - (scale > 0 ? 1 : 0) - (unsigned_flag || !length ? 0 : 1));
225  return retval;
226 }
227 
229  uint8 scale,
230  bool unsigned_flag) {
231  /*
232  When precision is 0 it means that original length was also 0. Thus
233  unsigned_flag is ignored in this case.
234  */
235  DBUG_ASSERT(precision || !scale);
236  uint32 retval = (uint32)(precision + (scale > 0 ? 1 : 0) +
237  (unsigned_flag || !precision ? 0 : 1));
238  return retval;
239 }
240 
242  bool unsigned_flag) {
243  /*
244  When precision is 0 it means that original length was also 0. Thus
245  unsigned_flag is ignored in this case.
246  */
247  DBUG_ASSERT(precision || !scale);
249  return my_decimal_precision_to_length_no_truncation(precision, scale,
250  unsigned_flag);
251 }
252 
253 inline int my_decimal_string_length(const my_decimal *d) {
254  /* length of string representation including terminating '\0' */
255  return decimal_string_size(d);
256 }
257 
258 inline int my_decimal_get_binary_size(uint precision, uint scale) {
259  return decimal_bin_size((int)precision, (int)scale);
260 }
261 
262 inline void my_decimal2decimal(const my_decimal *from, my_decimal *to) {
263  *to = *from;
264 }
265 
266 int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec,
267  int scale);
268 
269 inline int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d,
270  int prec, int scale) {
271  return d->check_result(mask, bin2decimal(bin, d, prec, scale, false));
272 }
273 
274 /**
275  Decode DECIMAL from binary form
276 
277  @param mask Error mask
278  @param bin Binary string to decode
279  @param d [out] DECIMAL buffer
280  @param prec Precision of stored value
281  @param scale Scale of stored value
282  @param keep_prec Whether to keep stored value's precision
283 
284  @returns
285  conversion error
286 */
287 
288 inline int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d,
289  int prec, int scale, bool keep_prec) {
290  return d->check_result(mask, bin2decimal(bin, d, prec, scale, keep_prec));
291 }
292 
294  /*
295  We need the up-cast here, since my_decimal has sign() member functions,
296  which conflicts with decimal_t::size
297  (and decimal_make_zero is a macro, rather than a funcion).
298  */
299  decimal_make_zero(static_cast<decimal_t *>(d));
300  return 0;
301 }
302 
303 inline bool my_decimal_is_zero(const my_decimal *decimal_value) {
304  return decimal_is_zero(decimal_value);
305 }
306 
307 inline int my_decimal_round(uint mask, const my_decimal *from, int scale,
308  bool truncate, my_decimal *to) {
309  return from->check_result(
310  mask, decimal_round(from, to, scale, (truncate ? TRUNCATE : HALF_UP)));
311 }
312 
313 inline int my_decimal_floor(uint mask, const my_decimal *from, my_decimal *to) {
314  return from->check_result(mask, decimal_round(from, to, 0, FLOOR));
315 }
316 
317 inline int my_decimal_ceiling(uint mask, const my_decimal *from,
318  my_decimal *to) {
319  return from->check_result(mask, decimal_round(from, to, 0, CEILING));
320 }
321 
322 inline bool str_set_decimal(const my_decimal *val, String *str,
323  const CHARSET_INFO *cs) {
324  return str_set_decimal(E_DEC_FATAL_ERROR, val, 0, 0, 0, str, cs);
325 }
326 
327 int my_decimal2string(uint mask, const my_decimal *d, uint fixed_prec,
328  uint fixed_dec, char filler, String *str);
329 
330 inline int my_decimal2int(uint mask, const my_decimal *d, bool unsigned_flag,
331  longlong *l) {
332  my_decimal rounded;
333  /* decimal_round can return only E_DEC_TRUNCATED */
334  decimal_round(d, &rounded, 0, HALF_UP);
335  return d->check_result(
336  mask, (unsigned_flag ? decimal2ulonglong(&rounded, (ulonglong *)l)
337  : decimal2longlong(&rounded, l)));
338 }
339 
340 inline int my_decimal2double(uint, const my_decimal *d, double *result) {
341  /* No need to call check_result as this will always succeed */
342  return decimal2double(d, result);
343 }
344 
345 inline int my_decimal2lldiv_t(uint mask, const my_decimal *d, lldiv_t *to) {
346  return d->check_result(mask, decimal2lldiv_t(d, to));
347 }
348 
349 inline int str2my_decimal(uint mask, const char *str, my_decimal *d,
350  const char **end) {
351  return check_result_and_overflow(mask, string2decimal(str, d, end), d);
352 }
353 
354 int str2my_decimal(uint mask, const char *from, size_t length,
355  const CHARSET_INFO *charset, my_decimal *decimal_value);
356 
357 inline int string2my_decimal(uint mask, const String *str, my_decimal *d) {
358  return str2my_decimal(mask, str->ptr(), (uint)str->length(), str->charset(),
359  d);
360 }
361 
362 my_decimal *date2my_decimal(const MYSQL_TIME *ltime, my_decimal *dec);
363 my_decimal *time2my_decimal(const MYSQL_TIME *ltime, my_decimal *dec);
364 my_decimal *timeval2my_decimal(const struct timeval *tm, my_decimal *dec);
365 
366 inline int double2my_decimal(uint mask, double val, my_decimal *d) {
367  return check_result_and_overflow(mask, double2decimal(val, d), d);
368 }
369 
370 inline int int2my_decimal(uint mask, longlong i, bool unsigned_flag,
371  my_decimal *d) {
372  return d->check_result(mask,
373  (unsigned_flag ? ulonglong2decimal((ulonglong)i, d)
374  : longlong2decimal(i, d)));
375 }
376 
377 inline void my_decimal_neg(decimal_t *arg) {
378  // Avoid returning negative zero, cfr. decimal_cmp()
379  if (decimal_is_zero(arg)) {
380  arg->sign = 0;
381  return;
382  }
383  arg->sign ^= 1;
384 }
385 
386 inline int my_decimal_add(uint mask, my_decimal *res, const my_decimal *a,
387  const my_decimal *b) {
388  return check_result_and_overflow(mask, decimal_add(a, b, res), res);
389 }
390 
391 inline int my_decimal_sub(uint mask, my_decimal *res, const my_decimal *a,
392  const my_decimal *b) {
393  return check_result_and_overflow(mask, decimal_sub(a, b, res), res);
394 }
395 
396 inline int my_decimal_mul(uint mask, my_decimal *res, const my_decimal *a,
397  const my_decimal *b) {
398  return check_result_and_overflow(mask, decimal_mul(a, b, res), res);
399 }
400 
401 inline int my_decimal_div(uint mask, my_decimal *res, const my_decimal *a,
402  const my_decimal *b, int div_scale_inc) {
403  return check_result_and_overflow(mask, decimal_div(a, b, res, div_scale_inc),
404  res);
405 }
406 
407 inline int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a,
408  const my_decimal *b) {
409  return check_result_and_overflow(mask, decimal_mod(a, b, res), res);
410 }
411 
412 /**
413  @return
414  @retval -1 if a @< b
415  @retval 1 if a @> b
416  @retval 0 if a == b
417 */
418 inline int my_decimal_cmp(const my_decimal *a, const my_decimal *b) {
419  return decimal_cmp(a, b);
420 }
421 
422 inline bool operator<(const my_decimal &lhs, const my_decimal &rhs) {
423  return my_decimal_cmp(&lhs, &rhs) < 0;
424 }
425 
426 inline bool operator!=(const my_decimal &lhs, const my_decimal &rhs) {
427  return my_decimal_cmp(&lhs, &rhs) != 0;
428 }
429 
430 inline int my_decimal_intg(const my_decimal *a) { return decimal_intg(a); }
431 
432 void my_decimal_trim(ulong *precision, uint *scale);
433 
434 #endif // MY_DECIMAL_INCLUDED
int int2my_decimal(uint mask, longlong i, bool unsigned_flag, my_decimal *d)
Definition: my_decimal.h:370
bool sign() const
Definition: my_decimal.h:164
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:314
Some common macros.
unsigned long long int ulonglong
Definition: my_inttypes.h:74
unsigned char uchar
Definition: my_inttypes.h:51
int intg
Definition: decimal.h:52
Our own string classes, used pervasively throughout the executor.
uint32 my_decimal_precision_to_length(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:241
int double2decimal(double from, decimal_t *to)
Definition: decimal.cc:1045
int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:407
int string2my_decimal(uint mask, const String *str, my_decimal *d)
Definition: my_decimal.h:357
decimal_digit_t * buf
Definition: decimal.h:54
static mi_bit_type mask[]
Definition: mi_packrec.cc:138
int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale, bool keep_prec=false)
Definition: decimal.cc:1450
~my_decimal()
Definition: my_decimal.h:155
int my_decimal_get_binary_size(uint precision, uint scale)
Definition: my_decimal.h:258
Some integer typedefs for easier portability.
void max_decimal(int precision, int frac, decimal_t *to)
Definition: decimal.cc:396
int decimal_cmp(const decimal_t *from1, const decimal_t *from2)
Definition: decimal.cc:2047
int my_decimal2string(uint mask, const my_decimal *d, uint fixed_prec, uint fixed_dec, char filler, String *str)
Converting decimal to string.
Definition: my_decimal.cc:119
void my_decimal_trim(ulong *precision, uint *scale)
Definition: my_decimal.cc:331
int my_decimal2int(uint mask, const my_decimal *d, bool unsigned_flag, longlong *l)
Definition: my_decimal.h:330
int frac
Definition: decimal.h:52
int foo2
Definition: my_decimal.h:114
int decimal2lldiv_t(const decimal_t *from, lldiv_t *to)
Convert decimal to lldiv_t.
Definition: decimal.cc:1175
int my_decimal_string_length(const my_decimal *d)
Definition: my_decimal.h:253
Definition: decimal.h:38
my_decimal(const my_decimal &rhs)
Definition: my_decimal.h:119
my_decimal()
Definition: my_decimal.h:152
int my_decimal_round(uint mask, const my_decimal *from, int scale, bool truncate, my_decimal *to)
Definition: my_decimal.h:307
int my_decimal_ceiling(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:317
int32 decimal_digit_t
Definition: decimal.h:40
int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2086
bool operator!=(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:426
int my_decimal_mul(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:396
void my_decimal2decimal(const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:262
int my_decimal_cmp(const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:418
static const int test_value
Definition: my_decimal.h:115
int longlong2decimal(longlong from, decimal_t *to)
Definition: decimal.cc:1091
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
int decimal_mod(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2513
bool operator<(const my_decimal &lhs, const my_decimal &rhs)
Definition: my_decimal.h:422
#define set_if_smaller(a, b)
Definition: my_macros.h:67
int decimal2double(const decimal_t *from, double *to)
Definition: decimal.cc:1016
void max_internal_decimal(my_decimal *to)
Definition: my_decimal.h:199
bool my_decimal_is_zero(const my_decimal *decimal_value)
Definition: my_decimal.h:303
decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]
Definition: my_decimal.h:111
int my_decimal_int_part(uint precision, uint decimals)
Definition: my_decimal.h:88
int decimal_bin_size(int precision, int scale)
Definition: decimal.cc:1596
#define DBUG_ASSERT(A)
Definition: my_dbug.h:183
uint my_decimal_size(uint precision, uint scale)
Definition: my_decimal.h:80
int foo1
Definition: my_decimal.h:108
int my_decimal2double(uint, const my_decimal *d, double *result)
Definition: my_decimal.h:340
void sanity_check() const
Definition: my_decimal.h:158
int decimal_div(const decimal_t *from1, const decimal_t *from2, decimal_t *to, int scale_incr)
Definition: decimal.cc:2481
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:300
int my_decimal_floor(uint mask, const my_decimal *from, my_decimal *to)
Definition: my_decimal.h:313
void max_my_decimal(my_decimal *to, int precision, int frac)
Definition: my_decimal.h:193
uint precision() const
Definition: my_decimal.h:166
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
my_decimal class limits &#39;decimal_t&#39; type to what we need in MySQL.
Definition: my_decimal.h:100
int my_decimal_intg(const my_decimal *a)
Definition: my_decimal.h:430
#define E_DEC_FATAL_ERROR
Definition: decimal.h:146
int my_decimal_add(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:386
int decimal_add(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2037
int decimal_round(const decimal_t *from, decimal_t *to, int new_scale, decimal_round_mode mode)
Definition: decimal.cc:1618
unsigned int uint
Definition: uca-dump.cc:29
long long int longlong
Definition: my_inttypes.h:73
int binary2my_decimal(uint mask, const uchar *bin, my_decimal *d, int prec, int scale)
Definition: my_decimal.h:269
int decimal2longlong(decimal_t *from, longlong *to)
Definition: decimal.cc:1122
#define DECIMAL_NOT_SPECIFIED
Definition: my_decimal.h:67
uint32_t uint32
Definition: my_inttypes.h:62
#define DECIMAL_BUFF_LENGTH
maximum length of buffer in our big digits (uint32).
Definition: my_decimal.h:54
Definition: decimal.h:36
int my_decimal2lldiv_t(uint mask, const my_decimal *d, lldiv_t *to)
Definition: my_decimal.h:345
#define DECIMAL_MAX_SCALE
Definition: my_decimal.h:66
static void decimal_make_zero(decimal_t *dec)
Definition: decimal.h:114
int check_result_and_overflow(uint mask, int result, my_decimal *val)
Definition: my_decimal.h:203
void init()
Definition: my_decimal.h:139
Definition: m_ctype.h:359
uint8_t uint8
Definition: my_inttypes.h:58
const char * dbug_decimal_as_string(char *buff, const my_decimal *val)
Definition: my_decimal.cc:368
int decimal_is_zero(const decimal_t *from)
Definition: decimal.cc:2057
uint32 my_decimal_precision_to_length_no_truncation(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:228
void print_decimal_buff(const my_decimal *dec, const uchar *ptr, int length)
Definition: my_decimal.cc:359
my_decimal decimal_zero
Definition: mysqld.cc:1294
int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec, int scale)
Definition: my_decimal.cc:212
Definition: mysql_time.h:64
int check_result(uint, int result) const
report result of decimal operation.
Definition: my_decimal.cc:55
#define DECIMAL_MAX_PRECISION
maximum guaranteed precision of number in decimal digits (number of our digits * number of decimal di...
Definition: my_decimal.h:65
int decimal2ulonglong(decimal_t *from, ulonglong *to)
Definition: decimal.cc:1098
void sign(bool s)
Definition: my_decimal.h:165
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:401
void print_decimal(const my_decimal *dec)
Definition: my_decimal.cc:346
my_decimal & operator=(const my_decimal &rhs)
Definition: my_decimal.h:129
int decimal_sub(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
Definition: decimal.cc:2042
int string2decimal(const char *from, decimal_t *to, const char **end)
Definition: decimal.cc:876
#define E_DEC_OVERFLOW
Definition: decimal.h:140
bool str_set_decimal(uint mask, const my_decimal *val, uint fixed_prec, uint fixed_dec, char filler, String *str, const CHARSET_INFO *cs)
Converting decimal to string with character set conversion.
Definition: my_decimal.cc:168
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:583
uint my_decimal_length_to_precision(uint length, uint scale, bool unsigned_flag)
Definition: my_decimal.h:219
const CHARSET_INFO * charset() const
Definition: sql_string.h:232
A better implementation of the UNIX ctype(3) library.
int my_decimal_set_zero(my_decimal *d)
Definition: my_decimal.h:293
int str2my_decimal(uint mask, const char *str, my_decimal *d, const char **end)
Definition: my_decimal.h:349
void my_decimal_neg(decimal_t *arg)
Definition: my_decimal.h:377
const char * ptr() const
Definition: sql_string.h:241
void swap(my_decimal &rhs)
Swap two my_decimal values.
Definition: my_decimal.h:169
Definition: decimal.h:34
int ulonglong2decimal(ulonglong from, decimal_t *to)
Definition: decimal.cc:1086
int double2my_decimal(uint mask, double val, my_decimal *d)
Definition: my_decimal.h:366
int decimal_size(int precision, int scale)
Definition: decimal.cc:1571
unsigned long ulong
Definition: my_inttypes.h:48
bool sign
Definition: decimal.h:53
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
intg is the number of decimal digits (NOT number of decimal_digit_t&#39;s !) before the point frac is the...
Definition: decimal.h:51
size_t length() const
Definition: sql_string.h:233
int len
Definition: decimal.h:52
#define E_DEC_DIV_ZERO
Definition: decimal.h:141
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:125
int decimal_intg(const decimal_t *from)
Definition: decimal.cc:2031
Definition: decimal.h:37
my_decimal * timeval2my_decimal(const struct timeval *tm, my_decimal *dec)
Convert timeval value to my_decimal.
Definition: my_decimal.cc:324
int my_decimal_sub(uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
Definition: my_decimal.h:391