My Project
Classes | Defines | Typedefs | Functions | Variables
my_decimal.h File Reference
#include <decimal.h>

Go to the source code of this file.

Classes

class  my_decimal

Defines

#define DECIMAL_LONGLONG_DIGITS   22
#define DECIMAL_LONG_DIGITS   10
#define DECIMAL_LONG3_DIGITS   8
#define DECIMAL_BUFF_LENGTH   9
#define DECIMAL_MAX_POSSIBLE_PRECISION   (DECIMAL_BUFF_LENGTH * 9)
#define DECIMAL_MAX_PRECISION   (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2)
#define DECIMAL_MAX_SCALE   30
#define DECIMAL_NOT_SPECIFIED   31
#define DECIMAL_MAX_STR_LENGTH   (DECIMAL_MAX_POSSIBLE_PRECISION + 2)
#define DECIMAL_MAX_FIELD_SIZE   DECIMAL_MAX_PRECISION

Typedefs

typedef struct st_mysql_time MYSQL_TIME

Functions

uint my_decimal_size (uint precision, uint scale)
int my_decimal_int_part (uint precision, uint decimals)
void print_decimal (const my_decimal *dec)
void print_decimal_buff (const my_decimal *dec, const uchar *ptr, int length)
const char * dbug_decimal_as_string (char *buff, const my_decimal *val)
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.
int decimal_operation_results (int result)
void max_my_decimal (my_decimal *to, int precision, int frac)
void max_internal_decimal (my_decimal *to)
int check_result (uint mask, int result)
int check_result_and_overflow (uint mask, int result, my_decimal *val)
uint my_decimal_length_to_precision (uint length, uint scale, bool unsigned_flag)
uint32 my_decimal_precision_to_length_no_truncation (uint precision, uint8 scale, bool unsigned_flag)
uint32 my_decimal_precision_to_length (uint precision, uint8 scale, bool unsigned_flag)
int my_decimal_string_length (const my_decimal *d)
int my_decimal_max_length (const my_decimal *d)
int my_decimal_get_binary_size (uint precision, uint scale)
void my_decimal2decimal (const my_decimal *from, my_decimal *to)
int my_decimal2binary (uint mask, const my_decimal *d, uchar *bin, int prec, int scale)
int binary2my_decimal (uint mask, const uchar *bin, my_decimal *d, int prec, int scale)
int my_decimal_set_zero (my_decimal *d)
bool my_decimal_is_zero (const my_decimal *decimal_value)
int my_decimal_round (uint mask, const my_decimal *from, int scale, bool truncate, my_decimal *to)
int my_decimal_floor (uint mask, const my_decimal *from, my_decimal *to)
int my_decimal_ceiling (uint mask, const my_decimal *from, my_decimal *to)
bool str_set_decimal (const my_decimal *val, String *str, const CHARSET_INFO *cs)
int my_decimal2string (uint mask, const my_decimal *d, uint fixed_prec, uint fixed_dec, char filler, String *str)
 Converting decimal to string.
int my_decimal2int (uint mask, const my_decimal *d, my_bool unsigned_flag, longlong *l)
int my_decimal2double (uint, const my_decimal *d, double *result)
int my_decimal2lldiv_t (uint mask, const my_decimal *d, lldiv_t *to)
int str2my_decimal (uint mask, const char *str, my_decimal *d, char **end)
int str2my_decimal (uint mask, const char *from, uint length, const CHARSET_INFO *charset, my_decimal *decimal_value)
int double2my_decimal (uint mask, double val, my_decimal *d)
int int2my_decimal (uint mask, longlong i, my_bool unsigned_flag, my_decimal *d)
void my_decimal_neg (decimal_t *arg)
int my_decimal_add (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
int my_decimal_sub (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
int my_decimal_mul (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
int my_decimal_div (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b, int div_scale_inc)
int my_decimal_mod (uint mask, my_decimal *res, const my_decimal *a, const my_decimal *b)
int my_decimal_cmp (const my_decimal *a, const my_decimal *b)
int my_decimal_intg (const my_decimal *a)
void my_decimal_trim (ulong *precision, uint *scale)

Variables

my_decimal decimal_zero

Detailed Description

It is interface module to fixed precision decimals library.

Most functions use 'uint mask' as parameter, if during operation error which fit in this mask is detected then it will be processed automatically here. (errors are E_DEC_* constants, see include/decimal.h)

Most function are just inline wrappers around library calls


Define Documentation

#define DECIMAL_BUFF_LENGTH   9

maximum length of buffer in our big digits (uint32).

maximum size of packet length.

#define DECIMAL_MAX_PRECISION   (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2)

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_STR_LENGTH   (DECIMAL_MAX_POSSIBLE_PRECISION + 2)

maximum length of string representation (number of maximum decimal digits + 1 position for sign + 1 position for decimal point, no terminator)


Function Documentation

int decimal_operation_results ( int  result)

report result of decimal operation.

Parameters:
resultdecimal library return code (E_DEC_* see include/decimal.h)
Todo:
Fix error messages
Returns:
result
int my_decimal2string ( uint  mask,
const my_decimal d,
uint  fixed_prec,
uint  fixed_dec,
char  filler,
String str 
)

Converting decimal to string.

Convert given my_decimal to String; allocate buffer as needed.

Parameters:
[in]maskwhat problems to warn on (mask of E_DEC_* values)
[in]dthe decimal to print
[in]fixed_precoverall number of digits if ZEROFILL, 0 otherwise
[in]fixed_decnumber of decimal places (if fixed_prec != 0)
[in]fillerwhat char to pad with (ZEROFILL et al.)
[out]*strwhere to store the resulting string
Returns:
error coce
Return values:
E_DEC_OK
E_DEC_TRUNCATED
E_DEC_OVERFLOW
E_DEC_OOM
int my_decimal_cmp ( const my_decimal a,
const my_decimal b 
) [inline]
Returns:
-1 if a<b, 1 if a>b and 0 if a==b
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.

Convert given my_decimal to String; allocate buffer as needed.

Parameters:
[in]maskwhat problems to warn on (mask of E_DEC_* values)
[in]valthe decimal to print
[in]fixed_precoverall number of digits if ZEROFILL, 0 otherwise
[in]fixed_decnumber of decimal places (if fixed_prec != 0)
[in]fillerwhat char to pad with (ZEROFILL et al.)
[out]*strwhere to store the resulting string
[in]cscharacter set
Returns:
error coce
Return values:
E_DEC_OK
E_DEC_TRUNCATED
E_DEC_OVERFLOW
E_DEC_OOMWould be great to make it a method of the String class, but this would need to include my_decimal.h from sql_string.h and sql_string.cc, which is not desirable.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines