~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/decimal.h

  • Committer: Joseph Daly
  • Date: 2010-09-16 17:47:44 UTC
  • mto: (1774.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1775.
  • Revision ID: jdaly@rx7-20100916174744-9myzc6sigk4zrmtn
fix copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#ifndef DRIZZLED_DECIMAL_H
17
17
#define DRIZZLED_DECIMAL_H
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
 
inline int string2decimal(char *from, decimal_t *to, char **end)
67
 
{
68
 
  return internal_str2dec(from, to, end, false);
69
 
}
 
66
#define string2decimal(A,B,C) internal_str2dec((A), (B), (C), 0)
70
67
 
71
68
/* set a decimal_t to zero */
72
69
 
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
 
}
 
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)
80
76
 
81
77
/*
82
78
  returns the length of the buffer to hold string representation
83
79
  of the decimal (including decimal dot, possible sign and \0)
84
80
*/
85
81
 
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
 
}
 
82
#define decimal_string_size(dec) (((dec)->intg ? (dec)->intg : 1) + \
 
83
                                  (dec)->frac + ((dec)->frac > 0) + 2)
90
84
 
91
85
/* negate a decimal */
92
 
inline void decimal_neg(decimal_t *dec)
93
 
{
94
 
  dec->sign^=1;
95
 
}
 
86
#define decimal_neg(dec) do { (dec)->sign^=1; } while(0)
96
87
 
97
88
/*
98
89
  conventions:
169
160
  {
170
161
    len= DECIMAL_BUFF_LENGTH;
171
162
    buf= buffer;
172
 
        #if !defined (HAVE_VALGRIND)
 
163
        #if !defined (HAVE_purify)
173
164
                /* Set buffer to 'random' value to find wrong buffer usage */
174
165
                for (uint32_t i= 0; i < DECIMAL_BUFF_LENGTH; i++)
175
166
                  buffer[i]= i;