00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <drizzled/type/decimal.h>
00023 #include <drizzled/function/math/int_val.h>
00024
00025 namespace drizzled
00026 {
00027
00028 void Item_func_int_val::fix_num_length_and_dec()
00029 {
00030 max_length= args[0]->max_length - (args[0]->decimals ?
00031 args[0]->decimals + 1 :
00032 0) + 2;
00033 uint32_t tmp= float_length(decimals);
00034 set_if_smaller(max_length,tmp);
00035 decimals= 0;
00036 }
00037
00038 void Item_func_int_val::find_num_type()
00039 {
00040 switch(hybrid_type= args[0]->result_type())
00041 {
00042 case STRING_RESULT:
00043 case REAL_RESULT:
00044 hybrid_type= REAL_RESULT;
00045 max_length= float_length(decimals);
00046 break;
00047 case INT_RESULT:
00048 case DECIMAL_RESULT:
00049
00050
00051
00052
00053 if ((args[0]->max_length - args[0]->decimals) >=
00054 (DECIMAL_LONGLONG_DIGITS - 2))
00055 {
00056 hybrid_type= DECIMAL_RESULT;
00057 }
00058 else
00059 {
00060 unsigned_flag= args[0]->unsigned_flag;
00061 hybrid_type= INT_RESULT;
00062 }
00063 break;
00064 default:
00065 assert(0);
00066 }
00067 return;
00068 }
00069
00070 }