Drizzled Public API Documentation

multiply.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/math/multiply.h>
00023 
00024 #include <algorithm>
00025 
00026 using namespace std;
00027 
00028 namespace drizzled
00029 {
00030 
00031 double Item_func_mul::real_op()
00032 {
00033   assert(fixed == 1);
00034   double value= args[0]->val_real() * args[1]->val_real();
00035   if ((null_value=args[0]->null_value || args[1]->null_value))
00036     return 0.0;
00037   return fix_result(value);
00038 }
00039 
00040 
00041 int64_t Item_func_mul::int_op()
00042 {
00043   assert(fixed == 1);
00044   int64_t value=args[0]->val_int()*args[1]->val_int();
00045   if ((null_value=args[0]->null_value || args[1]->null_value))
00046     return 0;
00047   return value;
00048 }
00049 
00050 
00053 type::Decimal *Item_func_mul::decimal_op(type::Decimal *decimal_value)
00054 {
00055   type::Decimal value1, *val1;
00056   type::Decimal value2, *val2;
00057   val1= args[0]->val_decimal(&value1);
00058   if ((null_value= args[0]->null_value))
00059     return 0;
00060   val2= args[1]->val_decimal(&value2);
00061   if (!(null_value= (args[1]->null_value ||
00062                      (class_decimal_mul(E_DEC_FATAL_ERROR, decimal_value, val1,
00063                                     val2) > 3))))
00064     return decimal_value;
00065   return 0;
00066 }
00067 
00068 
00069 void Item_func_mul::result_precision()
00070 {
00071   /* Integer operations keep unsigned_flag if one of arguments is unsigned */
00072   if (result_type() == INT_RESULT)
00073     unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
00074   else
00075     unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
00076 
00077   decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
00078   int precision= min(args[0]->decimal_precision() + args[1]->decimal_precision(),
00079                      (unsigned int)DECIMAL_MAX_PRECISION);
00080   max_length= class_decimal_precision_to_length(precision, decimals,unsigned_flag);
00081 }
00082 
00083 } /* namespace drizzled */