diff options
Diffstat (limited to 'sql/my_decimal.h')
-rw-r--r-- | sql/my_decimal.h | 66 |
1 files changed, 23 insertions, 43 deletions
diff --git a/sql/my_decimal.h b/sql/my_decimal.h index 0f5a31e999c..5eae7a2f386 100644 --- a/sql/my_decimal.h +++ b/sql/my_decimal.h @@ -34,32 +34,7 @@ C_MODE_START #include <decimal.h> C_MODE_END -#define DECIMAL_LONGLONG_DIGITS 22 -#define DECIMAL_LONG_DIGITS 10 -#define DECIMAL_LONG3_DIGITS 8 - -/** maximum length of buffer in our big digits (uint32). */ -#define DECIMAL_BUFF_LENGTH 9 - -/* the number of digits that my_decimal can possibly contain */ -#define DECIMAL_MAX_POSSIBLE_PRECISION (DECIMAL_BUFF_LENGTH * 9) - - -/** - maximum guaranteed precision of number in decimal digits (number of our - digits * number of decimal digits in one our big digit - number of decimal - digits in one our big digit decreased by 1 (because we always put decimal - point on the border of our big digits)) -*/ -#define DECIMAL_MAX_PRECISION (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2) -#define DECIMAL_MAX_SCALE 30 -#define DECIMAL_NOT_SPECIFIED 31 - -/** - maximum length of string representation (number of maximum decimal - digits + 1 position for sign + 1 position for decimal point, no terminator) -*/ -#define DECIMAL_MAX_STR_LENGTH (DECIMAL_MAX_POSSIBLE_PRECISION + 2) +#include <my_decimal_limits.h> /** maximum size of packet length. @@ -163,9 +138,10 @@ const char *dbug_decimal_as_string(char *buff, const my_decimal *val); #endif #ifndef MYSQL_CLIENT -int decimal_operation_results(int result); +int decimal_operation_results(int result, const char *value, const char *type); #else -inline int decimal_operation_results(int result) +inline int decimal_operation_results(int result, const char *value, + const char *type) { return result; } @@ -187,7 +163,7 @@ inline void max_internal_decimal(my_decimal *to) inline int check_result(uint mask, int result) { if (result & mask) - decimal_operation_results(result); + decimal_operation_results(result, "", "DECIMAL"); return result; } @@ -324,24 +300,19 @@ int my_decimal2string(uint mask, const my_decimal *d, uint fixed_prec, uint fixed_dec, char filler, String *str); #endif -inline -int my_decimal2int(uint mask, const my_decimal *d, my_bool unsigned_flag, - longlong *l) -{ - my_decimal rounded; - /* decimal_round can return only E_DEC_TRUNCATED */ - decimal_round((decimal_t*)d, &rounded, 0, HALF_UP); - return check_result(mask, (unsigned_flag ? - decimal2ulonglong(&rounded, (ulonglong *)l) : - decimal2longlong(&rounded, l))); -} +bool my_decimal2seconds(const my_decimal *d, ulonglong *sec, ulong *microsec); +my_decimal *seconds2my_decimal(bool sign, ulonglong sec, ulong microsec, + my_decimal *d); + +int my_decimal2int(uint mask, const decimal_t *d, bool unsigned_flag, + longlong *l); inline -int my_decimal2double(uint, const my_decimal *d, double *result) +int my_decimal2double(uint, const decimal_t *d, double *result) { /* No need to call check_result as this will always succeed */ - return decimal2double((decimal_t*) d, result); + return decimal2double(d, result); } @@ -384,6 +355,16 @@ int int2my_decimal(uint mask, longlong i, my_bool unsigned_flag, my_decimal *d) longlong2decimal(i, d))); } +inline +void decimal2my_decimal(decimal_t *from, my_decimal *to) +{ + DBUG_ASSERT(to->len >= from->len); + to->intg= from->intg; + to->frac= from->frac; + to->sign(from->sign); + memcpy(to->buf, from->buf, to->len*sizeof(decimal_digit_t)); +} + inline void my_decimal_neg(decimal_t *arg) @@ -447,7 +428,6 @@ int my_decimal_mod(uint mask, my_decimal *res, const my_decimal *a, res); } - /** @return -1 if a<b, 1 if a>b and 0 if a==b |