~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/additive_op.cc

  • Committer: Monty Taylor
  • Date: 2008-11-16 06:29:53 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116062953-ivdltjmfe009b5fr
Moved stuff into item/

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
22
 
#include <drizzled/function/additive_op.h>
23
 
 
24
 
#include <algorithm>
25
 
 
26
 
using namespace std;
27
 
 
28
 
namespace drizzled
29
 
{
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include <drizzled/functions/additive_op.h>
30
23
 
31
24
/**
32
25
  Set precision of results for additive operations (+ and -)
33
26
*/
34
27
void Item_func_additive_op::result_precision()
35
28
{
36
 
  decimals= max(args[0]->decimals, args[1]->decimals);
37
 
  int max_int_part= max(args[0]->decimal_precision() - args[0]->decimals,
 
29
  decimals= cmax(args[0]->decimals, args[1]->decimals);
 
30
  int max_int_part= cmax(args[0]->decimal_precision() - args[0]->decimals,
38
31
                        args[1]->decimal_precision() - args[1]->decimals);
39
 
  int precision= min(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
 
32
  int precision= cmin(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
40
33
 
41
34
  /* Integer operations keep unsigned_flag if one of arguments is unsigned */
42
35
  if (result_type() == INT_RESULT)
43
36
    unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
44
37
  else
45
38
    unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
46
 
 
47
39
  max_length= my_decimal_precision_to_length(precision, decimals,
48
40
                                             unsigned_flag);
49
41
}
50
42
 
51
 
} /* namespace drizzled */