00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021 #include <math.h>
00022 #include "floor.h"
00023
00024 #include <drizzled/type/decimal.h>
00025
00026 namespace drizzled
00027 {
00028
00029 int64_t Item_func_floor::int_op()
00030 {
00031 int64_t result;
00032 switch (args[0]->result_type()) {
00033 case INT_RESULT:
00034 result= args[0]->val_int();
00035 null_value= args[0]->null_value;
00036 break;
00037 case DECIMAL_RESULT:
00038 {
00039 type::Decimal dec_buf, *dec;
00040 if ((dec= Item_func_floor::decimal_op(&dec_buf)))
00041 dec->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
00042 else
00043 result= 0;
00044 break;
00045 }
00046 default:
00047 result= (int64_t)Item_func_floor::real_op();
00048 };
00049 return result;
00050 }
00051
00052 double Item_func_floor::real_op()
00053 {
00054
00055
00056
00057
00058 volatile double value= args[0]->val_real();
00059 null_value= args[0]->null_value;
00060 return floor(value);
00061 }
00062
00063
00064 type::Decimal *Item_func_floor::decimal_op(type::Decimal *decimal_value)
00065 {
00066 type::Decimal val, *value= args[0]->val_decimal(&val);
00067 if (!(null_value= (args[0]->null_value ||
00068 class_decimal_floor(E_DEC_FATAL_ERROR, value,
00069 decimal_value) > 1)))
00070 return decimal_value;
00071 return 0;
00072 }
00073
00074 }