List:Internals« Previous MessageNext Message »
From:jimw Date:January 13 2005 12:41am
Subject:bk commit into 4.1 tree (jimw:1.2207)
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of jwinstead2. When jwinstead2 does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet
  1.2207 05/01/13 00:41:45 jimw@stripped +4 -0
  Fix conversion of floating point values to character fields when the
  absolute value of the float is less than 1, and also fix calculation of
  length for negative values. (Bug #7774)

  mysql-test/t/type_float.test
    1.15 05/01/13 00:39:44 jimw@stripped +10 -0
    Add test for conversion of floats to character field

  mysql-test/r/type_float.result.es
    1.4 05/01/13 00:38:47 jimw@stripped +15 -0
    Add results

  mysql-test/r/type_float.result
    1.27 05/01/13 00:38:42 jimw@stripped +15 -0
    Add results

  sql/field.cc
    1.204 05/01/13 00:03:26 jimw@stripped +10 -4
    Fix handling of negative values and fabs(values> < 1 in Field_str::store

  sql/field.cc
    1.203 05/01/12 04:33:44 jimw@stripped +3 -2
    Skip setting use_scientific_notation to FALSE for values less than 1
    and take - into account for negative numbers.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	jimw
# Host:	play01.mysql.com
# Root:	/home/jwinstead2/mysql-4.1-7774

--- 1.202/sql/field.cc	Fri Jan  7 17:43:30 2005
+++ 1.204/sql/field.cc	Thu Jan 13 00:03:26 2005
@@ -4301,13 +4301,20 @@
   char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
   uint length;
   bool use_scientific_notation= TRUE;
-  use_scientific_notation= TRUE;
-  if (field_length < 32 && fabs(nr) < log_10[field_length]-1)
+  /*
+    Check fabs(nr) against longest value that can be stored in field,
+    which depends on whether the value is < 1 or not, and negative or not
+  */
+  double anr= fabs(nr);
+  int neg= (nr < 0.0) ? 1 : 0;
+  if (field_length < 32 &&
+      (anr < 1.0 ? anr > 1/(log_10[max(0,field_length-neg-2)]) /* -2 for "0." */
+                 : anr < log_10[field_length-neg]-1))
     use_scientific_notation= FALSE;
 
   length= (uint) my_sprintf(buff, (buff, "%-.*g",
                                    (use_scientific_notation ?
-                                    max(0, (int)field_length-5) :
+                                    max(0, (int)field_length-neg-5) :
                                     field_length),
                                    nr));
   /*

--- 1.3/mysql-test/r/type_float.result.es	Fri Jan  7 17:43:18 2005
+++ 1.4/mysql-test/r/type_float.result.es	Thu Jan 13 00:38:47 2005
@@ -179,3 +179,18 @@
 9.999
 9.999
 drop table if exists t1;
+create table t1 (c char(20));
+insert into t1 values (5e-28);
+select * from t1;
+c
+5e-28
+drop table t1;
+create table t1 (c char(6));
+insert into t1 values (2e5),(2e6),(2e-4),(2e-5);
+select * from t1;
+c
+200000
+2e+06
+0.0002
+2e-05
+drop table t1;

--- 1.26/mysql-test/r/type_float.result	Fri Jan  7 17:43:14 2005
+++ 1.27/mysql-test/r/type_float.result	Thu Jan 13 00:38:42 2005
@@ -179,3 +179,18 @@
 9.999
 9.999
 drop table if exists t1;
+create table t1 (c char(20));
+insert into t1 values (5e-28);
+select * from t1;
+c
+5e-28
+drop table t1;
+create table t1 (c char(6));
+insert into t1 values (2e5),(2e6),(2e-4),(2e-5);
+select * from t1;
+c
+200000
+2e+06
+0.0002
+2e-05
+drop table t1;

--- 1.14/mysql-test/t/type_float.test	Fri Jan  7 17:42:56 2005
+++ 1.15/mysql-test/t/type_float.test	Thu Jan 13 00:39:44 2005
@@ -103,3 +103,13 @@
 insert into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11");
 select * from t1;
 drop table if exists t1;
+
+# Check conversion of floats to character field (Bug #7774)
+create table t1 (c char(20));
+insert into t1 values (5e-28);
+select * from t1;
+drop table t1;
+create table t1 (c char(6));
+insert into t1 values (2e5),(2e6),(2e-4),(2e-5);
+select * from t1;
+drop table t1;
Thread
bk commit into 4.1 tree (jimw:1.2207)jimw13 Jan