Drizzled Public API Documentation

ceiling.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 #include <math.h>
00022 #include "ceiling.h"
00023 #include <drizzled/type/decimal.h>
00024 
00025 namespace drizzled
00026 {
00027 
00028 int64_t Item_func_ceiling::int_op()
00029 {
00030   int64_t result;
00031   switch (args[0]->result_type()) {
00032   case INT_RESULT:
00033     result= args[0]->val_int();
00034     null_value= args[0]->null_value;
00035     break;
00036   case DECIMAL_RESULT:
00037   {
00038     type::Decimal dec_buf, *dec;
00039     if ((dec= Item_func_ceiling::decimal_op(&dec_buf)))
00040       dec->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
00041     else
00042       result= 0;
00043     break;
00044   }
00045   default:
00046     result= (int64_t)Item_func_ceiling::real_op();
00047   };
00048   return result;
00049 }
00050 
00051 double Item_func_ceiling::real_op()
00052 {
00053   /*
00054     the volatile's for BUG #3051 to calm optimizer down (because of gcc's
00055     bug)
00056   */
00057   volatile double value= args[0]->val_real();
00058   null_value= args[0]->null_value;
00059   return ceil(value);
00060 }
00061 
00062 type::Decimal *Item_func_ceiling::decimal_op(type::Decimal *decimal_value)
00063 {
00064   type::Decimal val, *value= args[0]->val_decimal(&val);
00065   if (!(null_value= (args[0]->null_value ||
00066                      class_decimal_ceiling(E_DEC_FATAL_ERROR, value,
00067                                         decimal_value) > 1)))
00068     return decimal_value;
00069   return 0;
00070 }
00071 
00072 } /* namespace drizzled */