~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/decimal.h

  • Committer: Brian Aker
  • Date: 2010-12-25 00:28:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2031.
  • Revision ID: brian@tangent.org-20101225002849-g73mg6ihulajis0o
First pass in refactoring of the name of my_decimal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
*/
146
146
#define DECIMAL_MAX_FIELD_SIZE DECIMAL_MAX_PRECISION
147
147
 
148
 
inline int my_decimal_int_part(uint32_t precision, uint32_t decimals)
 
148
inline int class_decimal_int_part(uint32_t precision, uint32_t decimals)
149
149
{
150
150
  return precision - ((decimals == DECIMAL_NOT_SPECIFIED) ? 0 : decimals);
151
151
}
221
221
  return result;
222
222
}
223
223
 
224
 
inline uint32_t my_decimal_length_to_precision(uint32_t length, uint32_t scale,
 
224
inline uint32_t class_decimal_length_to_precision(uint32_t length, uint32_t scale,
225
225
                                           bool unsigned_flag)
226
226
{
227
227
  return (uint32_t) (length - (scale>0 ? 1:0) - (unsigned_flag ? 0:1));
228
228
}
229
229
 
230
 
inline uint32_t my_decimal_precision_to_length(uint32_t precision, uint8_t scale,
 
230
inline uint32_t class_decimal_precision_to_length(uint32_t precision, uint8_t scale,
231
231
                                             bool unsigned_flag)
232
232
{
233
233
  set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
235
235
}
236
236
 
237
237
inline
238
 
int my_decimal_string_length(const my_decimal *d)
 
238
int class_decimal_string_length(const my_decimal *d)
239
239
{
240
240
  return decimal_string_size(d);
241
241
}
242
242
 
243
243
 
244
244
inline
245
 
int my_decimal_max_length(const my_decimal *d)
 
245
int class_decimal_max_length(const my_decimal *d)
246
246
{
247
247
  /* -1 because we do not count \0 */
248
248
  return decimal_string_size(d) - 1;
250
250
 
251
251
 
252
252
inline
253
 
int my_decimal_get_binary_size(uint32_t precision, uint32_t scale)
 
253
int class_decimal_get_binary_size(uint32_t precision, uint32_t scale)
254
254
{
255
255
  return decimal_bin_size(static_cast<int>(precision), static_cast<int>(scale));
256
256
}
277
277
 
278
278
 
279
279
inline
280
 
int my_decimal_set_zero(my_decimal *d)
 
280
int class_decimal_set_zero(my_decimal *d)
281
281
{
282
282
  decimal_make_zero(static_cast<decimal_t*> (d));
283
283
  return 0;
285
285
 
286
286
 
287
287
inline
288
 
bool my_decimal_is_zero(const my_decimal *decimal_value)
 
288
bool class_decimal_is_zero(const my_decimal *decimal_value)
289
289
{
290
290
  return decimal_is_zero(static_cast<const decimal_t*>(decimal_value));
291
291
}
292
292
 
293
293
 
294
294
inline
295
 
int my_decimal_round(uint32_t mask, const my_decimal *from, int scale,
 
295
int class_decimal_round(uint32_t mask, const my_decimal *from, int scale,
296
296
                     bool truncate, my_decimal *to)
297
297
{
298
298
  return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, scale,
301
301
 
302
302
 
303
303
inline
304
 
int my_decimal_floor(uint32_t mask, const my_decimal *from, my_decimal *to)
 
304
int class_decimal_floor(uint32_t mask, const my_decimal *from, my_decimal *to)
305
305
{
306
306
  return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, 0, FLOOR));
307
307
}
308
308
 
309
309
 
310
310
inline
311
 
int my_decimal_ceiling(uint32_t mask, const my_decimal *from, my_decimal *to)
 
311
int class_decimal_ceiling(uint32_t mask, const my_decimal *from, my_decimal *to)
312
312
{
313
313
  return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, 0, CEILING));
314
314
}
376
376
 
377
377
 
378
378
inline
379
 
void my_decimal_neg(decimal_t *arg)
 
379
void class_decimal_neg(decimal_t *arg)
380
380
{
381
381
  if (decimal_is_zero(arg))
382
382
  {
388
388
 
389
389
 
390
390
inline
391
 
int my_decimal_add(uint32_t mask, my_decimal *res, const my_decimal *a,
 
391
int class_decimal_add(uint32_t mask, my_decimal *res, const my_decimal *a,
392
392
                   const my_decimal *b)
393
393
{
394
394
  return check_result_and_overflow(mask,
399
399
 
400
400
 
401
401
inline
402
 
int my_decimal_sub(uint32_t mask, my_decimal *res, const my_decimal *a,
 
402
int class_decimal_sub(uint32_t mask, my_decimal *res, const my_decimal *a,
403
403
                   const my_decimal *b)
404
404
{
405
405
  return check_result_and_overflow(mask,
410
410
 
411
411
 
412
412
inline
413
 
int my_decimal_mul(uint32_t mask, my_decimal *res, const my_decimal *a,
 
413
int class_decimal_mul(uint32_t mask, my_decimal *res, const my_decimal *a,
414
414
                   const my_decimal *b)
415
415
{
416
416
  return check_result_and_overflow(mask,
421
421
 
422
422
 
423
423
inline
424
 
int my_decimal_div(uint32_t mask, my_decimal *res, const my_decimal *a,
 
424
int class_decimal_div(uint32_t mask, my_decimal *res, const my_decimal *a,
425
425
                   const my_decimal *b, int div_scale_inc)
426
426
{
427
427
  return check_result_and_overflow(mask,
433
433
 
434
434
 
435
435
inline
436
 
int my_decimal_mod(uint32_t mask, my_decimal *res, const my_decimal *a,
 
436
int class_decimal_mod(uint32_t mask, my_decimal *res, const my_decimal *a,
437
437
                   const my_decimal *b)
438
438
{
439
439
  return check_result_and_overflow(mask,
448
448
    -1 if a<b, 1 if a>b and 0 if a==b
449
449
*/
450
450
inline
451
 
int my_decimal_cmp(const my_decimal *a, const my_decimal *b)
 
451
int class_decimal_cmp(const my_decimal *a, const my_decimal *b)
452
452
{
453
453
  return decimal_cmp(static_cast<const decimal_t*>(a),
454
454
                     static_cast<const decimal_t*>(b));
456
456
 
457
457
 
458
458
inline
459
 
int my_decimal_intg(const my_decimal *a)
 
459
int class_decimal_intg(const my_decimal *a)
460
460
{
461
461
  return decimal_intg(static_cast<const decimal_t*>(a));
462
462
}
463
463
 
464
464
 
465
 
void my_decimal_trim(uint32_t *precision, uint32_t *scale);
 
465
void class_decimal_trim(uint32_t *precision, uint32_t *scale);
466
466
 
467
467
} /* namespace drizzled */
468
468