Drizzled Public API Documentation

minus.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/minus.h>
00023 #include <drizzled/type/decimal.h>
00024 
00025 namespace drizzled
00026 {
00027 
00033 void Item_func_minus::fix_length_and_dec()
00034 {
00035   Item_num_op::fix_length_and_dec();
00036   if (unsigned_flag)
00037     unsigned_flag= 0;
00038 }
00039 
00040 
00041 double Item_func_minus::real_op()
00042 {
00043   double value= args[0]->val_real() - args[1]->val_real();
00044   if ((null_value=args[0]->null_value || args[1]->null_value))
00045     return 0.0;
00046   return fix_result(value);
00047 }
00048 
00049 
00050 int64_t Item_func_minus::int_op()
00051 {
00052   int64_t value=args[0]->val_int() - args[1]->val_int();
00053   if ((null_value=args[0]->null_value || args[1]->null_value))
00054     return 0;
00055   return value;
00056 }
00057 
00062 type::Decimal *Item_func_minus::decimal_op(type::Decimal *decimal_value)
00063 {
00064   type::Decimal value1, *val1;
00065   type::Decimal value2, *val2=
00066 
00067   val1= args[0]->val_decimal(&value1);
00068   if ((null_value= args[0]->null_value))
00069     return 0;
00070   val2= args[1]->val_decimal(&value2);
00071   if (!(null_value= (args[1]->null_value ||
00072                      (class_decimal_sub(E_DEC_FATAL_ERROR, decimal_value, val1,
00073                                      val2) > 3))))
00074     return decimal_value;
00075   return 0;
00076 }
00077 
00078 } /* namespace drizzled */