Merge lp:~gthorslund/drizzle/replace-macro-functions into lp:drizzle/7.0

Proposed by Gustaf Thorslund
Status: Merged
Approved by: Brian Aker
Approved revision: no longer in the source branch.
Merged at revision: 1892
Proposed branch: lp:~gthorslund/drizzle/replace-macro-functions
Merge into: lp:drizzle/7.0
Diff against target: 652 lines (+157/-157)
2 files modified
drizzled/decimal.cc (+138/-147)
drizzled/decimal.h (+19/-10)
To merge this branch: bzr merge lp:~gthorslund/drizzle/replace-macro-functions
Reviewer Review Type Date Requested Status
Drizzle Developers Pending
Review via email: mp+39656@code.launchpad.net

Description of the change

  Replaced macros with functions/templates. Part of blueprint:
    https://blueprints.edge.launchpad.net/drizzle/+spec/replace-macro-functions/
  Files done:
    drizzled/decimal.cc
    drizzled/decimal.h

To post a comment you must log in.
1892. By Lee Bieber

Merge Gustaf- Replaced macros with functions/templates

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'drizzled/decimal.cc'
2--- drizzled/decimal.cc 2010-10-20 20:25:52 +0000
3+++ drizzled/decimal.cc 2010-10-29 19:47:53 +0000
4@@ -363,7 +363,13 @@
5 #define DIG_MASK 100000000
6 #define DIG_BASE 1000000000
7 #define DIG_MAX (DIG_BASE-1)
8-#define ROUND_UP(X) (((X)+DIG_PER_DEC1-1)/DIG_PER_DEC1)
9+
10+template<typename T>
11+inline static T round_up(const T &x)
12+{
13+ return (x+DIG_PER_DEC1-1)/DIG_PER_DEC1;
14+}
15+
16 static const dec1 powers10[DIG_PER_DEC1+1]={
17 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
18 static const int dig2bytes[DIG_PER_DEC1+1]={0, 1, 1, 2, 2, 3, 3, 4, 4, 4};
19@@ -379,86 +385,71 @@
20 (d)->buf[(d)->len-1] | 1))
21 #endif
22
23-#define FIX_INTG_FRAC_ERROR(len, intg1, frac1, error) \
24- do \
25- { \
26- if (unlikely(intg1+frac1 > (len))) \
27- { \
28- if (unlikely(intg1 > (len))) \
29- { \
30- intg1=(len); \
31- frac1=0; \
32- error=E_DEC_OVERFLOW; \
33- } \
34- else \
35- { \
36- frac1=(len)-intg1; \
37- error=E_DEC_TRUNCATED; \
38- } \
39- } \
40- else \
41- error=E_DEC_OK; \
42- } while(0)
43-
44-#define ADD(to, from1, from2, carry) /* assume carry <= 1 */ \
45- do \
46- { \
47- dec1 a=(from1)+(from2)+(carry); \
48- assert((carry) <= 1); \
49- if (((carry)= a >= DIG_BASE)) /* no division here! */ \
50- a-=DIG_BASE; \
51- (to)=a; \
52- } while(0)
53-
54-#define ADD2(to, from1, from2, carry) \
55- do \
56- { \
57- dec2 a=((dec2)(from1))+(from2)+(carry); \
58- if (((carry)= a >= DIG_BASE)) \
59- a-=DIG_BASE; \
60- if (unlikely(a >= DIG_BASE)) \
61- { \
62- a-=DIG_BASE; \
63- carry++; \
64- } \
65- (to)=(dec1) a; \
66- } while(0)
67-
68-#define SUB(to, from1, from2, carry) /* to=from1-from2 */ \
69- do \
70- { \
71- dec1 a=(from1)-(from2)-(carry); \
72- if (((carry)= a < 0)) \
73- a+=DIG_BASE; \
74- (to)=a; \
75- } while(0)
76-
77-#define SUB2(to, from1, from2, carry) /* to=from1-from2 */ \
78- do \
79- { \
80- dec1 a=(from1)-(from2)-(carry); \
81- if (((carry)= a < 0)) \
82- a+=DIG_BASE; \
83- if (unlikely(a < 0)) \
84- { \
85- a+=DIG_BASE; \
86- carry++; \
87- } \
88- (to)=a; \
89- } while(0)
90-
91-/**
92- Swap the contents of two variables.
93- */
94-#define swap_variables(TYPE, a, b) \
95- do { \
96- TYPE dummy; \
97- dummy= a; \
98- a= b; \
99- b= dummy; \
100- } while (0)
101-
102-
103+inline static void fix_intg_frac_error(const int len, int &intg1, int &frac1, int &error)
104+{
105+ if (unlikely(intg1+frac1 > len))
106+ {
107+ if (unlikely(intg1 > len))
108+ {
109+ intg1=(len);
110+ frac1=0;
111+ error=E_DEC_OVERFLOW;
112+ }
113+ else
114+ {
115+ frac1=(len)-intg1;
116+ error=E_DEC_TRUNCATED;
117+ }
118+ }
119+ else
120+ error=E_DEC_OK;
121+}
122+
123+/* assume carry <= 1 */
124+inline static void add(dec1 &to, const dec1 &from1, const dec1& from2, dec1 &carry)
125+{
126+ dec1 a=from1+from2+carry;
127+ assert(carry <= 1);
128+ if ((carry= (a >= DIG_BASE))) /* no division here! */
129+ a-=DIG_BASE;
130+ to=a;
131+}
132+
133+inline static void add2(dec1 &to, const dec1 &from1, const dec1 &from2, dec1 &carry)
134+{
135+ dec2 a=dec2(from1)+from2+carry;
136+ if ((carry= (a >= DIG_BASE)))
137+ a-=DIG_BASE;
138+ if (unlikely(a >= DIG_BASE))
139+ {
140+ a-=DIG_BASE;
141+ carry++;
142+ }
143+ to=dec1(a);
144+}
145+
146+/* to=from1-from2 */
147+inline static void sub(dec1 &to, const dec1 &from1, const dec1 &from2, dec1 &carry)
148+{
149+ dec1 a=from1-from2-carry;
150+ if ((carry= (a < 0)))
151+ a+=DIG_BASE;
152+ to=a;
153+}
154+
155+/* to=from1-from2 */
156+inline static void sub2(dec1 &to, const dec1 &from1, const dec1 &from2, dec1 &carry)
157+{
158+ dec1 a=from1-from2-carry;
159+ if ((carry= (a < 0)))
160+ a+=DIG_BASE;
161+ if (unlikely(a < 0))
162+ {
163+ a+=DIG_BASE;
164+ carry++;
165+ }
166+ to=a;
167+}
168
169 /**
170 @brief Get maximum value for given precision and scale
171@@ -527,7 +518,7 @@
172 int decimal_actual_fraction(decimal_t *from)
173 {
174 int frac= from->frac, i;
175- dec1 *buf0= from->buf + ROUND_UP(from->intg) + ROUND_UP(frac) - 1;
176+ dec1 *buf0= from->buf + round_up(from->intg) + round_up(frac) - 1;
177
178 if (frac == 0)
179 return 0;
180@@ -632,7 +623,7 @@
181 {
182 char *s1= s + intg_len;
183 fill= frac_len - frac;
184- buf=buf0+ROUND_UP(intg);
185+ buf=buf0+round_up(intg);
186 *s1++='.';
187 for (; frac>0; frac-=DIG_PER_DEC1)
188 {
189@@ -657,7 +648,7 @@
190 if (intg)
191 {
192 s+=intg;
193- for (buf=buf0+ROUND_UP(intg); intg>0; intg-=DIG_PER_DEC1)
194+ for (buf=buf0+round_up(intg); intg>0; intg-=DIG_PER_DEC1)
195 {
196 dec1 x=*--buf;
197 for (i=min(intg, DIG_PER_DEC1); i; i--)
198@@ -687,7 +678,7 @@
199 {
200 int start, stop, i;
201 dec1 *buf_beg= from->buf;
202- dec1 *end= from->buf + ROUND_UP(from->intg) + ROUND_UP(from->frac);
203+ dec1 *end= from->buf + round_up(from->intg) + round_up(from->frac);
204 dec1 *buf_end= end - 1;
205
206 /* find non-zero digit from number begining */
207@@ -753,8 +744,8 @@
208 */
209 static void do_mini_left_shift(decimal_t *dec, int shift, int beg, int last)
210 {
211- dec1 *from= dec->buf + ROUND_UP(beg + 1) - 1;
212- dec1 *end= dec->buf + ROUND_UP(last) - 1;
213+ dec1 *from= dec->buf + round_up(beg + 1) - 1;
214+ dec1 *end= dec->buf + round_up(last) - 1;
215 int c_shift= DIG_PER_DEC1 - shift;
216 assert(from >= dec->buf);
217 assert(end < dec->buf + dec->len);
218@@ -781,8 +772,8 @@
219 */
220 static void do_mini_right_shift(decimal_t *dec, int shift, int beg, int last)
221 {
222- dec1 *from= dec->buf + ROUND_UP(last) - 1;
223- dec1 *end= dec->buf + ROUND_UP(beg + 1) - 1;
224+ dec1 *from= dec->buf + round_up(last) - 1;
225+ dec1 *end= dec->buf + round_up(beg + 1) - 1;
226 int c_shift= DIG_PER_DEC1 - shift;
227 assert(from < dec->buf + dec->len);
228 assert(end >= dec->buf);
229@@ -818,7 +809,7 @@
230 /* index of position after last decimal digit */
231 int end;
232 /* index of digit position just after point */
233- int point= ROUND_UP(dec->intg) * DIG_PER_DEC1;
234+ int point= round_up(dec->intg) * DIG_PER_DEC1;
235 /* new point position */
236 int new_point= point + shift;
237 /* number of digits in result */
238@@ -845,7 +836,7 @@
239 digits_frac= end - new_point;
240 set_if_bigger(digits_frac, 0);
241
242- if ((new_len= ROUND_UP(digits_int) + (new_frac_len= ROUND_UP(digits_frac))) >
243+ if ((new_len= round_up(digits_int) + (new_frac_len= round_up(digits_frac))) >
244 dec->len)
245 {
246 int lack= new_len - dec->len;
247@@ -938,8 +929,8 @@
248 {
249 /* move left */
250 d_shift= new_front / DIG_PER_DEC1;
251- to= dec->buf + (ROUND_UP(beg + 1) - 1 - d_shift);
252- barier= dec->buf + (ROUND_UP(end) - 1 - d_shift);
253+ to= dec->buf + (round_up(beg + 1) - 1 - d_shift);
254+ barier= dec->buf + (round_up(end) - 1 - d_shift);
255 assert(to >= dec->buf);
256 assert(barier + d_shift < dec->buf + dec->len);
257 for(; to <= barier; to++)
258@@ -952,8 +943,8 @@
259 {
260 /* move right */
261 d_shift= (1 - new_front) / DIG_PER_DEC1;
262- to= dec->buf + ROUND_UP(end) - 1 + d_shift;
263- barier= dec->buf + ROUND_UP(beg + 1) - 1 + d_shift;
264+ to= dec->buf + round_up(end) - 1 + d_shift;
265+ barier= dec->buf + round_up(beg + 1) - 1 + d_shift;
266 assert(to < dec->buf + dec->len);
267 assert(barier - d_shift >= dec->buf);
268 for(; to >= barier; to--)
269@@ -972,13 +963,13 @@
270
271 Only one of following 'for' loops will work becouse beg <= end
272 */
273- beg= ROUND_UP(beg + 1) - 1;
274- end= ROUND_UP(end) - 1;
275+ beg= round_up(beg + 1) - 1;
276+ end= round_up(end) - 1;
277 assert(new_point >= 0);
278
279 /* We don't want negative new_point below */
280 if (new_point != 0)
281- new_point= ROUND_UP(new_point) - 1;
282+ new_point= round_up(new_point) - 1;
283
284 if (new_point > end)
285 {
286@@ -1073,8 +1064,8 @@
287 error=E_DEC_OVERFLOW;
288 intg=to->intg;
289 }
290- intg1=ROUND_UP(intg);
291- frac1=ROUND_UP(frac);
292+ intg1=round_up(intg);
293+ frac1=round_up(frac);
294 if (intg1+frac1 > to->len)
295 {
296 error= E_DEC_OOM;
297@@ -1083,9 +1074,9 @@
298 }
299 else
300 {
301- intg1=ROUND_UP(intg);
302- frac1=ROUND_UP(frac);
303- FIX_INTG_FRAC_ERROR(to->len, intg1, frac1, error);
304+ intg1=round_up(intg);
305+ frac1=round_up(frac);
306+ fix_intg_frac_error(to->len, intg1, frac1, error);
307 if (unlikely(error))
308 {
309 frac=frac1*DIG_PER_DEC1;
310@@ -1549,7 +1540,7 @@
311 d_copy[0]^= 0x80;
312 from= d_copy;
313
314- FIX_INTG_FRAC_ERROR(to->len, intg1, frac1, error);
315+ fix_intg_frac_error(to->len, intg1, frac1, error);
316 if (unlikely(error))
317 {
318 if (intg1 < intg0+(intg0x>0))
319@@ -1669,10 +1660,10 @@
320 decimal_round(const decimal_t *from, decimal_t *to, int scale,
321 decimal_round_mode mode)
322 {
323- int frac0=scale>0 ? ROUND_UP(scale) : scale/DIG_PER_DEC1,
324- frac1=ROUND_UP(from->frac), round_digit= 0,
325- intg0=ROUND_UP(from->intg), error=E_DEC_OK, len=to->len,
326- intg1=ROUND_UP(from->intg +
327+ int frac0=scale>0 ? round_up(scale) : scale/DIG_PER_DEC1,
328+ frac1=round_up(from->frac), round_digit= 0,
329+ intg0=round_up(from->intg), error=E_DEC_OK, len=to->len,
330+ intg1=round_up(from->intg +
331 (((intg0 + frac0)>0) && (from->buf[0] == DIG_MAX)));
332 dec1 *buf0=from->buf, *buf1=to->buf, x, y, carry=0;
333 int first_dig;
334@@ -1807,7 +1798,7 @@
335 carry=1;
336 *buf1-=DIG_BASE;
337 while (carry && --buf1 >= to->buf)
338- ADD(*buf1, *buf1, 0, carry);
339+ add(*buf1, *buf1, 0, carry);
340 if (unlikely(carry))
341 {
342 /* shifting the number to create space for new digit */
343@@ -1860,8 +1851,8 @@
344
345 static int do_add(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
346 {
347- int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
348- frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac),
349+ int intg1=round_up(from1->intg), intg2=round_up(from2->intg),
350+ frac1=round_up(from1->frac), frac2=round_up(from2->frac),
351 frac0=max(frac1, frac2), intg0=max(intg1, intg2), error;
352 dec1 *buf1, *buf2, *buf0, *stop, *stop2, x, carry;
353
354@@ -1877,7 +1868,7 @@
355 to->buf[0]=0; /* safety */
356 }
357
358- FIX_INTG_FRAC_ERROR(to->len, intg0, frac0, error);
359+ fix_intg_frac_error(to->len, intg0, frac0, error);
360 if (unlikely(error == E_DEC_OVERFLOW))
361 {
362 max_decimal(to->len * DIG_PER_DEC1, 0, to);
363@@ -1920,7 +1911,7 @@
364 carry=0;
365 while (buf1 > stop2)
366 {
367- ADD(*--buf0, *--buf1, *--buf2, carry);
368+ add(*--buf0, *--buf1, *--buf2, carry);
369 }
370
371 /* part 3 - cmin(intg) ... cmax(intg) */
372@@ -1928,7 +1919,7 @@
373 ((stop=from2->buf)+intg2-intg1) ;
374 while (buf1 > stop)
375 {
376- ADD(*--buf0, *--buf1, 0, carry);
377+ add(*--buf0, *--buf1, 0, carry);
378 }
379
380 if (unlikely(carry))
381@@ -1942,8 +1933,8 @@
382 if to==0, return -1/0/+1 - the result of the comparison */
383 static int do_sub(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
384 {
385- int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
386- frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac);
387+ int intg1=round_up(from1->intg), intg2=round_up(from2->intg),
388+ frac1=round_up(from1->frac), frac2=round_up(from2->frac);
389 int frac0=max(frac1, frac2), error;
390 dec1 *buf1, *buf2, *buf0, *stop1, *stop2, *start1, *start2, carry=0;
391
392@@ -2009,14 +2000,14 @@
393 /* ensure that always from1 > from2 (and intg1 >= intg2) */
394 if (carry)
395 {
396- swap_variables(const decimal_t *,from1, from2);
397- swap_variables(dec1 *,start1, start2);
398- swap_variables(int,intg1,intg2);
399- swap_variables(int,frac1,frac2);
400+ swap(from1, from2);
401+ swap(start1, start2);
402+ swap(intg1, intg2);
403+ swap(frac1, frac2);
404 to->sign= 1 - to->sign;
405 }
406
407- FIX_INTG_FRAC_ERROR(to->len, intg1, frac0, error);
408+ fix_intg_frac_error(to->len, intg1, frac0, error);
409 buf0=to->buf+intg1+frac0;
410
411 to->frac=max(from1->frac, from2->frac);
412@@ -2050,20 +2041,20 @@
413 *--buf0=0;
414 while (buf2 > stop2)
415 {
416- SUB(*--buf0, 0, *--buf2, carry);
417+ sub(*--buf0, 0, *--buf2, carry);
418 }
419 }
420
421 /* part 2 - cmin(frac) ... intg2 */
422 while (buf2 > start2)
423 {
424- SUB(*--buf0, *--buf1, *--buf2, carry);
425+ sub(*--buf0, *--buf1, *--buf2, carry);
426 }
427
428 /* part 3 - intg2 ... intg1 */
429 while (carry && buf1 > start1)
430 {
431- SUB(*--buf0, *--buf1, 0, carry);
432+ sub(*--buf0, *--buf1, 0, carry);
433 }
434
435 while (buf1 > start1)
436@@ -2107,7 +2098,7 @@
437 int decimal_is_zero(const decimal_t *from)
438 {
439 dec1 *buf1=from->buf,
440- *end=buf1+ROUND_UP(from->intg)+ROUND_UP(from->frac);
441+ *end=buf1+round_up(from->intg)+round_up(from->frac);
442 while (buf1 < end)
443 if (*buf1++)
444 return 0;
445@@ -2136,9 +2127,9 @@
446 */
447 int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to)
448 {
449- int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
450- frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac),
451- intg0=ROUND_UP(from1->intg+from2->intg),
452+ int intg1=round_up(from1->intg), intg2=round_up(from2->intg),
453+ frac1=round_up(from1->frac), frac2=round_up(from2->frac),
454+ intg0=round_up(from1->intg+from2->intg),
455 frac0=frac1+frac2, error, i, j, d_to_move;
456 dec1 *buf1=from1->buf+intg1, *buf2=from2->buf+intg2, *buf0,
457 *start2, *stop2, *stop1, *start0, carry;
458@@ -2147,7 +2138,7 @@
459
460 i=intg0;
461 j=frac0;
462- FIX_INTG_FRAC_ERROR(to->len, intg0, frac0, error);
463+ fix_intg_frac_error(to->len, intg0, frac0, error);
464 to->sign=from1->sign != from2->sign;
465 to->frac=from1->frac+from2->frac;
466 to->intg=intg0*DIG_PER_DEC1;
467@@ -2188,20 +2179,20 @@
468 dec2 p= ((dec2)*buf1) * ((dec2)*buf2);
469 hi=(dec1)(p/DIG_BASE);
470 lo=(dec1)(p-((dec2)hi)*DIG_BASE);
471- ADD2(*buf0, *buf0, lo, carry);
472+ add2(*buf0, *buf0, lo, carry);
473 carry+=hi;
474 }
475 if (carry)
476 {
477 if (buf0 < to->buf)
478 return E_DEC_OVERFLOW;
479- ADD2(*buf0, *buf0, 0, carry);
480+ add2(*buf0, *buf0, 0, carry);
481 }
482 for (buf0--; carry; buf0--)
483 {
484 if (buf0 < to->buf)
485 return E_DEC_OVERFLOW;
486- ADD(*buf0, *buf0, 0, carry);
487+ add(*buf0, *buf0, 0, carry);
488 }
489 }
490
491@@ -2224,7 +2215,7 @@
492 }
493 }
494 buf1= to->buf;
495- d_to_move= intg0 + ROUND_UP(to->frac);
496+ d_to_move= intg0 + round_up(to->frac);
497 while (!*buf1 && (to->intg > DIG_PER_DEC1))
498 {
499 buf1++;
500@@ -2254,8 +2245,8 @@
501 static int do_div_mod(const decimal_t *from1, const decimal_t *from2,
502 decimal_t *to, decimal_t *mod, int scale_incr)
503 {
504- int frac1=ROUND_UP(from1->frac)*DIG_PER_DEC1, prec1=from1->intg+frac1,
505- frac2=ROUND_UP(from2->frac)*DIG_PER_DEC1, prec2=from2->intg+frac2,
506+ int frac1=round_up(from1->frac)*DIG_PER_DEC1, prec1=from1->intg+frac1,
507+ frac2=round_up(from2->frac)*DIG_PER_DEC1, prec2=from2->intg+frac2,
508 error= 0, i, intg0, frac0, len1, len2, dintg, div_mod=(!mod);
509 dec1 *buf0, *buf1=from1->buf, *buf2=from2->buf, *tmp1,
510 *start2, *stop2, *stop1, *stop0, norm2, carry, *start1, dcarry;
511@@ -2305,7 +2296,7 @@
512 intg0=0;
513 }
514 else
515- intg0=ROUND_UP(dintg);
516+ intg0=round_up(dintg);
517 if (mod)
518 {
519 /* we're calculating N1 % N2.
520@@ -2324,13 +2315,13 @@
521 N2 is in the buf2, has prec2 digits. Scales are frac1 and
522 frac2 accordingly.
523 Thus, the result will have
524- frac = ROUND_UP(frac1+frac2+scale_incr)
525+ frac = round_up(frac1+frac2+scale_incr)
526 and
527 intg = (prec1-frac1) - (prec2-frac2) + 1
528 prec = intg+frac
529 */
530- frac0=ROUND_UP(frac1+frac2+scale_incr);
531- FIX_INTG_FRAC_ERROR(to->len, intg0, frac0, error);
532+ frac0=round_up(frac1+frac2+scale_incr);
533+ fix_intg_frac_error(to->len, intg0, frac0, error);
534 to->sign=from1->sign != from2->sign;
535 to->intg=intg0*DIG_PER_DEC1;
536 to->frac=frac0*DIG_PER_DEC1;
537@@ -2341,7 +2332,7 @@
538 while (dintg++ < 0)
539 *buf0++=0;
540
541- len1=(i=ROUND_UP(prec1))+ROUND_UP(2*frac2+scale_incr+1) + 1;
542+ len1=(i=round_up(prec1))+round_up(2*frac2+scale_incr+1) + 1;
543 set_if_bigger(len1, 3);
544 if (!(tmp1=(dec1 *)alloca(len1*sizeof(dec1))))
545 return E_DEC_OOM;
546@@ -2351,7 +2342,7 @@
547 start1=tmp1;
548 stop1=start1+len1;
549 start2=buf2;
550- stop2=buf2+ROUND_UP(prec2)-1;
551+ stop2=buf2+round_up(prec2)-1;
552
553 /* removing end zeroes */
554 while (*stop2 == 0 && stop2 >= start2)
555@@ -2410,7 +2401,7 @@
556 x=guess * (*--buf2);
557 hi=(dec1)(x/DIG_BASE);
558 lo=(dec1)(x-((dec2)hi)*DIG_BASE);
559- SUB2(*buf1, *buf1, lo, carry);
560+ sub2(*buf1, *buf1, lo, carry);
561 carry+=hi;
562 }
563 carry= dcarry < carry;
564@@ -2424,7 +2415,7 @@
565 buf1=start1+len2;
566 for (carry=0; buf2 > start2; buf1--)
567 {
568- ADD(*buf1, *buf1, *--buf2, carry);
569+ add(*buf1, *buf1, *--buf2, carry);
570 }
571 }
572 }
573@@ -2443,8 +2434,8 @@
574 if (dcarry)
575 *--start1=dcarry;
576 buf0=to->buf;
577- intg0=(int) (ROUND_UP(prec1-frac1)-(start1-tmp1));
578- frac0=ROUND_UP(to->frac);
579+ intg0=(int) (round_up(prec1-frac1)-(start1-tmp1));
580+ frac0=round_up(to->frac);
581 error=E_DEC_OK;
582 if (unlikely(frac0==0 && intg0==0))
583 {
584@@ -2474,7 +2465,7 @@
585 error=E_DEC_OVERFLOW;
586 goto done;
587 }
588- assert(intg0 <= ROUND_UP(from2->intg));
589+ assert(intg0 <= round_up(from2->intg));
590 stop1=start1+frac0+intg0;
591 to->intg=min(intg0*DIG_PER_DEC1, from2->intg);
592 }
593@@ -2554,7 +2545,7 @@
594 {
595 int i;
596 printf("/* intg=%d, frac=%d, sign=%d, buf[]={", d->intg, d->frac, d->sign);
597- for (i=0; i < ROUND_UP(d->frac)+ROUND_UP(d->intg)-1; i++)
598+ for (i=0; i < round_up(d->frac)+round_up(d->intg)-1; i++)
599 printf("%09d, ", d->buf[i]);
600 printf("%09d} */ ", d->buf[i]);
601 }
602
603=== modified file 'drizzled/decimal.h'
604--- drizzled/decimal.h 2010-10-20 20:25:52 +0000
605+++ drizzled/decimal.h 2010-10-29 19:47:53 +0000
606@@ -63,27 +63,36 @@
607 int decimal_is_zero(const decimal_t *from);
608 void max_decimal(int precision, int frac, decimal_t *to);
609
610-#define string2decimal(A,B,C) internal_str2dec((A), (B), (C), 0)
611+inline int string2decimal(char *from, decimal_t *to, char **end)
612+{
613+ return internal_str2dec(from, to, end, false);
614+}
615
616 /* set a decimal_t to zero */
617
618-#define decimal_make_zero(dec) do { \
619- (dec)->buf[0]=0; \
620- (dec)->intg=1; \
621- (dec)->frac=0; \
622- (dec)->sign=0; \
623- } while(0)
624+inline void decimal_make_zero(decimal_t *dec)
625+{
626+ dec->buf[0]=0;
627+ dec->intg=1;
628+ dec->frac=0;
629+ dec->sign=0;
630+}
631
632 /*
633 returns the length of the buffer to hold string representation
634 of the decimal (including decimal dot, possible sign and \0)
635 */
636
637-#define decimal_string_size(dec) (((dec)->intg ? (dec)->intg : 1) + \
638- (dec)->frac + ((dec)->frac > 0) + 2)
639+inline int decimal_string_size(const decimal_t *dec)
640+{
641+ return (dec->intg ? dec->intg : 1) + dec->frac + (dec->frac > 0) + 2;
642+}
643
644 /* negate a decimal */
645-#define decimal_neg(dec) do { (dec)->sign^=1; } while(0)
646+inline void decimal_neg(decimal_t *dec)
647+{
648+ dec->sign^=1;
649+}
650
651 /*
652 conventions:

Subscribers

People subscribed via source and target branches