Drizzled Public API Documentation

additive_op.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <drizzled/function/additive_op.h>
00023 #include <drizzled/type/decimal.h>
00024 
00025 #include <algorithm>
00026 
00027 using namespace std;
00028 
00029 namespace drizzled
00030 {
00031 
00035 void Item_func_additive_op::result_precision()
00036 {
00037   decimals= max(args[0]->decimals, args[1]->decimals);
00038   int max_int_part= max(args[0]->decimal_precision() - args[0]->decimals,
00039                         args[1]->decimal_precision() - args[1]->decimals);
00040   int precision= min(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
00041 
00042   /* Integer operations keep unsigned_flag if one of arguments is unsigned */
00043   if (result_type() == INT_RESULT)
00044     unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
00045   else
00046     unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
00047 
00048   max_length= class_decimal_precision_to_length(precision, decimals,
00049                                              unsigned_flag);
00050 }
00051 
00052 } /* namespace drizzled */