@@ -1003,25 +1003,66 @@ class Item_decimal_typecast :public Item_func
10031003};
10041004
10051005
1006- class Item_double_typecast : public Item_real_func
1006+ class Item_real_typecast : public Item_real_func
10071007{
1008+ protected:
1009+ double val_real_with_truncate (double max_value);
10081010public:
1009- Item_double_typecast (THD *thd, Item *a, uint len, uint dec):
1010- Item_real_func (thd, a)
1011+ Item_real_typecast (THD *thd, Item *a, uint len, uint dec)
1012+ : Item_real_func(thd, a)
10111013 {
10121014 decimals= (uint8) dec;
10131015 max_length= (uint32) len;
10141016 }
1015- double val_real ();
1017+ bool need_parentheses_in_default () { return true ; }
1018+ void print (String *str, enum_query_type query_type);
10161019 void fix_length_and_dec_generic () { maybe_null= 1 ; }
1020+ };
1021+
1022+
1023+ class Item_float_typecast :public Item_real_typecast
1024+ {
1025+ public:
1026+ Item_float_typecast (THD *thd, Item *a)
1027+ :Item_real_typecast(thd, a, MAX_FLOAT_STR_LENGTH, NOT_FIXED_DEC)
1028+ { }
1029+ const Type_handler *type_handler () const { return &type_handler_float; }
1030+ bool fix_length_and_dec ()
1031+ {
1032+ return
1033+ args[0 ]->type_handler ()->Item_float_typecast_fix_length_and_dec (this );
1034+ }
1035+ const char *func_name () const { return " float_typecast" ; }
1036+ double val_real ()
1037+ {
1038+ return (double ) (float ) val_real_with_truncate (FLT_MAX);
1039+ }
1040+ String *val_str (String*str)
1041+ {
1042+ Float nr (Item_float_typecast::val_real ());
1043+ if (null_value)
1044+ return 0 ;
1045+ nr.to_string (str, decimals);
1046+ return str;
1047+ }
1048+ Item *get_copy (THD *thd)
1049+ { return get_item_copy<Item_float_typecast>(thd, this ); }
1050+ };
1051+
1052+
1053+ class Item_double_typecast :public Item_real_typecast
1054+ {
1055+ public:
1056+ Item_double_typecast (THD *thd, Item *a, uint len, uint dec):
1057+ Item_real_typecast (thd, a, len, dec)
1058+ { }
10171059 bool fix_length_and_dec ()
10181060 {
10191061 return
10201062 args[0 ]->type_handler ()->Item_double_typecast_fix_length_and_dec (this );
10211063 }
10221064 const char *func_name () const { return " double_typecast" ; }
1023- virtual void print (String *str, enum_query_type query_type);
1024- bool need_parentheses_in_default () { return true ; }
1065+ double val_real () { return val_real_with_truncate (DBL_MAX); }
10251066 Item *get_copy (THD *thd)
10261067 { return get_item_copy<Item_double_typecast>(thd, this ); }
10271068};
0 commit comments