• unknown's avatar
    Fix for bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits" · f506f5ca
    unknown authored
    When storing a large number to a FLOAT or DOUBLE field with fixed length, it could be incorrectly truncated if the field's length was greater than 31.
    
    This patch also does some code cleanups to be able to reuse code which is common between Field_float::store() and Field_double::store().
    
    
    include/m_string.h:
      Added declarations for log_10 and log_01 from strtod.c
    mysql-test/r/type_float.result:
      Added the testcase for bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits"
    mysql-test/t/type_float.test:
      Added the testcase for bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits"
    sql/field.cc:
      Moved common code from Field_float::store() and Field_double:store() to Field_real::truncate()
      Fixed the algorithm to not truncate large input numbers if the field length is greater than 31.
      Fixed rounding to not depend on FLT_MAX/DBL_MAX constants.
    sql/field.h:
      Moved not_fixed member from Field_double to Field_real to allow code reuse between Field_float::store() and Field_double::store()
      Added truncate() method to Field_real which is used by both Field_float and Field_double
    sql/init.cc:
      log_10[] and log_01[] are now defined as statical arrays in strtod.c, no need to pre-computed them.
    sql/item_cmpfunc.cc:
      log_01[] now starts from 1e0, not from 1e-1 for consistency.
    sql/mysql_priv.h:
      Moved log_10[] and log_01[] from mysqld.cc to libmystrings.
    sql/mysqld.cc:
      Moved log_10[] and log_01[] from mysqld.cc to libmystrings.
    strings/strtod.c:
      Define and use log_10[] and log_01[] as static arrays of constants instead of values pre-computed at startup.
    f506f5ca
strtod.c 9.66 KB