Drizzled Public API Documentation

real.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 <drizzled/function/math/real.h>
00023 
00024 namespace drizzled
00025 {
00026 
00027 
00028 String *Item_real_func::val_str(String *str)
00029 {
00030   assert(fixed == 1);
00031   double nr= val_real();
00032   if (null_value)
00033     return 0;
00034   str->set_real(nr,decimals, &my_charset_bin);
00035   return str;
00036 }
00037 
00038 
00039 type::Decimal *Item_real_func::val_decimal(type::Decimal *decimal_value)
00040 {
00041   assert(fixed);
00042   double nr= val_real();
00043   if (null_value)
00044     return 0;
00045   double2_class_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
00046   return decimal_value;
00047 }
00048 
00049 int64_t Item_real_func::val_int()
00050 {
00051   assert(fixed == 1);
00052   return (int64_t) rint(val_real());
00053 }
00054 
00055 void Item_real_func::fix_length_and_dec()
00056 {
00057   decimals= NOT_FIXED_DEC;
00058   max_length= float_length(decimals);
00059 }
00060 
00061 } /* namespace drizzled */