~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/decimal.h

Merge Gustaf-  Replaced macros with functions/templates

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
int decimal_is_zero(const decimal_t *from);
64
64
void max_decimal(int precision, int frac, decimal_t *to);
65
65
 
66
 
#define string2decimal(A,B,C) internal_str2dec((A), (B), (C), 0)
 
66
inline int string2decimal(char *from, decimal_t *to, char **end)
 
67
{
 
68
  return internal_str2dec(from, to, end, false);
 
69
}
67
70
 
68
71
/* set a decimal_t to zero */
69
72
 
70
 
#define decimal_make_zero(dec)        do {                \
71
 
                                        (dec)->buf[0]=0;    \
72
 
                                        (dec)->intg=1;      \
73
 
                                        (dec)->frac=0;      \
74
 
                                        (dec)->sign=0;      \
75
 
                                      } while(0)
 
73
inline void decimal_make_zero(decimal_t *dec)
 
74
{                                                           
 
75
  dec->buf[0]=0;
 
76
  dec->intg=1;
 
77
  dec->frac=0;
 
78
  dec->sign=0; 
 
79
}
76
80
 
77
81
/*
78
82
  returns the length of the buffer to hold string representation
79
83
  of the decimal (including decimal dot, possible sign and \0)
80
84
*/
81
85
 
82
 
#define decimal_string_size(dec) (((dec)->intg ? (dec)->intg : 1) + \
83
 
                                  (dec)->frac + ((dec)->frac > 0) + 2)
 
86
inline int decimal_string_size(const decimal_t *dec)
 
87
{
 
88
  return (dec->intg ? dec->intg : 1) + dec->frac + (dec->frac > 0) + 2;
 
89
}
84
90
 
85
91
/* negate a decimal */
86
 
#define decimal_neg(dec) do { (dec)->sign^=1; } while(0)
 
92
inline void decimal_neg(decimal_t *dec)
 
93
{
 
94
  dec->sign^=1;
 
95
}
87
96
 
88
97
/*
89
98
  conventions: