~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/additive_op.cc

  • Committer: Stewart Smith
  • Date: 2009-07-02 17:18:18 UTC
  • mfrom: (1085 staging)
  • mto: This revision was merged to the branch mainline in revision 1089.
  • Revision ID: stewart@flamingspork.com-20090702171818-qrp4d403iw8tazlg
mergeĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include CSTDINT_H
22
22
#include <drizzled/function/additive_op.h>
23
23
 
 
24
#include <algorithm>
 
25
 
 
26
using namespace std;
 
27
 
24
28
/**
25
29
  Set precision of results for additive operations (+ and -)
26
30
*/
27
31
void Item_func_additive_op::result_precision()
28
32
{
29
 
  decimals= cmax(args[0]->decimals, args[1]->decimals);
30
 
  int max_int_part= cmax(args[0]->decimal_precision() - args[0]->decimals,
 
33
  decimals= max(args[0]->decimals, args[1]->decimals);
 
34
  int max_int_part= max(args[0]->decimal_precision() - args[0]->decimals,
31
35
                        args[1]->decimal_precision() - args[1]->decimals);
32
 
  int precision= cmin(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
 
36
  int precision= min(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
33
37
 
34
38
  /* Integer operations keep unsigned_flag if one of arguments is unsigned */
35
39
  if (result_type() == INT_RESULT)
36
40
    unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
37
41
  else
38
42
    unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
 
43
 
39
44
  max_length= my_decimal_precision_to_length(precision, decimals,
40
45
                                             unsigned_flag);
41
46
}