Changeset: 8d793a3b5397 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8d793a3b5397
Modified Files:
        clients/mapiclient/mclient.c
        clients/odbc/driver/ODBCConvert.c
        gdk/gdk_atoms.c
        monetdb5/extras/rapi/Tests/rapi02.stable.out
        monetdb5/mal/Tests/tst041.stable.out
        monetdb5/mal/Tests/tst042.stable.out
        monetdb5/mal/Tests/tst044.stable.out
        monetdb5/mal/Tests/tst045.stable.out
        monetdb5/mal/Tests/tst048.stable.out
        monetdb5/mal/Tests/tst061.stable.out
        monetdb5/mal/Tests/tst100.stable.out
        monetdb5/mal/Tests/tst101.stable.out
        monetdb5/mal/Tests/tst171.stable.out
        monetdb5/mal/Tests/tst275.stable.out
        monetdb5/mal/Tests/tst401.stable.out
        monetdb5/mal/Tests/tst500.stable.out
        monetdb5/mal/Tests/tst700.stable.out
        monetdb5/mal/mal_parser.c
        monetdb5/modules/atoms/Tests/json15.stable.out
        monetdb5/modules/mal/Tests/bigsum.stable.out
        monetdb5/modules/mal/Tests/printf.stable.out
        monetdb5/modules/mal/Tests/remote02.stable.out
        monetdb5/optimizer/Tests/cst00.stable.out
        monetdb5/optimizer/Tests/cst01.stable.out
        monetdb5/tests/gdkTests/Tests/casts.stable.out
        monetdb5/tests/gdkTests/Tests/casts.stable.out.Windows
        monetdb5/tests/gdkTests/Tests/casts.stable.out.Windows.64bit.oid64
        monetdb5/tests/gdkTests/Tests/casts.stable.out.oid64
        sql/backends/monet5/generator/Tests/generator02.stable.out
        sql/test/BugTracker-2011/Tests/double_erange.Bug-2774.stable.out
        sql/test/BugTracker-2013/Tests/select-around-zero.Bug-3220.stable.out
        sql/test/BugTracker-2014/Tests/groupby.Bug-3421.stable.out
        sql/test/BugTracker-2014/Tests/groupby.Bug-3421.stable.out.int128
        sql/test/Dump/Tests/dump.stable.out
        sql/test/testdb-upgrade-chain/Tests/dump.stable.out
        sql/test/testdb-upgrade/Tests/dump.stable.out
        sql/test/testdb/Tests/testdb-dump.stable.out
Branch: default
Log Message:

Improve handling of floating point number on input and on output.
In MAL, we now don't go through flt when parsing a number with a :dbl
type attached.  See the difference in
b:= 0.345e1:dbl; io.print(b);
before and after the change.

On output, we now try to use the smallest precision that still gives
us the correct result.  This means that we will see things like 0.1
instead of 0.10000000000000001.


diffs (truncated from 3241 to 300 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1037,10 +1037,27 @@ TESTrenderer(MapiHdl hdl)
                                }
                                mnstr_write(toConsole, "\"", 1, 1);
                        } else if (strcmp(tp, "double") == 0 ||
-                                  strcmp(tp, "dbl") == 0 ||
-                                  strcmp(tp, "real") == 0)
-                               mnstr_printf(toConsole, "%.10g", atof(s));
-                       else
+                                  strcmp(tp, "dbl") == 0) {
+                               char buf[32];
+                               int j;
+                               double v = strtod(s, NULL);
+                               for (j = 4; j < 11; j++) {
+                                       snprintf(buf, sizeof(buf), "%.*g", j, 
v);
+                                       if (v == strtod(buf, NULL))
+                                               break;
+                               }
+                               mnstr_printf(toConsole, "%s", buf);
+                       } else if (strcmp(tp, "real") == 0) {
+                               char buf[32];
+                               int j;
+                               float v = strtof(s, NULL);
+                               for (j = 4; j < 6; j++) {
+                                       snprintf(buf, sizeof(buf), "%.*g", j, 
v);
+                                       if (v == strtof(buf, NULL))
+                                               break;
+                               }
+                               mnstr_printf(toConsole, "%s", buf);
+                       } else
                                mnstr_printf(toConsole, "%s", s);
                }
                mnstr_printf(toConsole, "\t]\n");
diff --git a/clients/odbc/driver/ODBCConvert.c 
b/clients/odbc/driver/ODBCConvert.c
--- a/clients/odbc/driver/ODBCConvert.c
+++ b/clients/odbc/driver/ODBCConvert.c
@@ -1371,7 +1371,7 @@ ODBCFetch(ODBCStmt *stmt,
                case SQL_REAL: {
                        data = (char *) ptr;
 
-                       for (i = 0; i < 18; i++) {
+                       for (i = 4; i < 18; i++) {
                                sz = (SQLLEN) snprintf(data, buflen, "%.*g", i, 
fval);
                                if (sz < 0 || sz >= buflen) {
                                        data[buflen - 1] = 0;
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -844,7 +844,23 @@ dblFromStr(const char *src, int *len, db
        return (int) (p - src);
 }
 
-atomtostr(dbl, "%.17g", (double))
+int
+dblToStr(char **dst, int *len, const dbl *src)
+{
+       int i;
+
+       atommem(char, dblStrlen);
+       if (*src == dbl_nil) {
+               return snprintf(*dst, *len, "nil");
+       }
+       for (i = 4; i < 18; i++) {
+               snprintf(*dst, *len, "%.*g", i, *src);
+               if (strtod(*dst, NULL) == *src)
+                       break;
+       }
+       return (int) strlen(*dst);
+}
+
 atom_io(dbl, Lng, lng)
 
 #ifdef _MSC_VER
@@ -912,7 +928,23 @@ fltFromStr(const char *src, int *len, fl
        return n;
 }
 
-atomtostr(flt, "%.9g", (float))
+int
+fltToStr(char **dst, int *len, const flt *src)
+{
+       int i;
+
+       atommem(char, fltStrlen);
+       if (*src == flt_nil) {
+               return snprintf(*dst, *len, "nil");
+       }
+       for (i = 4; i < 10; i++) {
+               snprintf(*dst, *len, "%.*g", i, *src);
+               if (strtof(*dst, NULL) == *src)
+                       break;
+       }
+       return (int) strlen(*dst);
+}
+
 atom_io(flt, Int, int)
 
 
diff --git a/monetdb5/extras/rapi/Tests/rapi02.stable.out 
b/monetdb5/extras/rapi/Tests/rapi02.stable.out
--- a/monetdb5/extras/rapi/Tests/rapi02.stable.out
+++ b/monetdb5/extras/rapi/Tests/rapi02.stable.out
@@ -100,10 +100,10 @@ Ready.
 # h    t  # name
 # void dbl  # type
 #--------------------------#
-[ 0@0, 17495052.91     ]
-[ 1@0, 12259.65625     ]
-[ 2@0, -16797856.47    ]
-[ 3@0, 12259.65625     ]
+[ 0@0, 17495052.06     ]
+[ 1@0, 12259.6606      ]
+[ 2@0, -16797855.63    ]
+[ 3@0, 12259.6606      ]
 #io.print(rstr);
 #--------------------------#
 # h    t  # name
diff --git a/monetdb5/mal/Tests/tst041.stable.out 
b/monetdb5/mal/Tests/tst041.stable.out
--- a/monetdb5/mal/Tests/tst041.stable.out
+++ b/monetdb5/mal/Tests/tst041.stable.out
@@ -100,7 +100,7 @@ function user.main():void;
     io.print(c);
     c := nil:bit;
     io.print(c);
-    d := 3.1400001:flt;
+    d := 3.14:flt;
     io.print(d);
     d := calc.flt(nil);
     io.print(d);
@@ -148,11 +148,11 @@ end user.main;
 [ true ]
 [ false ]
 [ nil ]
-[ 3.1400001 ]
+[ 3.14 ]
 [ nil ]
 [ nil ]
 [ 5 ]
-[ 7.13999987 ]
+[ 7.14 ]
 [ nil ]
 [ "hello" ]
 [ nil ]
diff --git a/monetdb5/mal/Tests/tst042.stable.out 
b/monetdb5/mal/Tests/tst042.stable.out
--- a/monetdb5/mal/Tests/tst042.stable.out
+++ b/monetdb5/mal/Tests/tst042.stable.out
@@ -39,7 +39,7 @@ stdout of test 'tst042` in directory 'mo
 function user.main():void;
     s := "hello";
     i := 1;
-    f := 3.1400001;
+    f := 3.14;
     b := true;
     w := 1:wrd;
     B := 2:bte;
diff --git a/monetdb5/mal/Tests/tst044.stable.out 
b/monetdb5/mal/Tests/tst044.stable.out
--- a/monetdb5/mal/Tests/tst044.stable.out
+++ b/monetdb5/mal/Tests/tst044.stable.out
@@ -26,31 +26,31 @@ stdout of test 'tst044` in directory 'mo
 #
 function user.main():void;
 #testing floating point numbers; 
-    a := 3.14499998:flt;
+    a := 3.145:flt;
     io.print(a);
-    a := -3.14499998:flt;
+    a := -3.145:flt;
     io.print(a);
-    a := 3.45000005:flt;
+    a := 3.45:flt;
     io.print(a);
-    a := 0.341500014:flt;
+    a := 0.3415:flt;
     io.print(a);
-    b := 3.1449999809265137:dbl;
+    b := 3.145:dbl;
     io.print(b);
-    b := -3.1449999809265137:dbl;
+    b := -3.145:dbl;
     io.print(b);
-    b := 3.4500000476837158:dbl;
+    b := 3.45:dbl;
     io.print(b);
-    b := 0.34150001406669617:dbl;
+    b := 0.3415:dbl;
     io.print(b);
 end user.main;
-[ 3.14499998 ]
-[ -3.14499998 ]
-[ 3.45000005 ]
-[ 0.341500014 ]
-[ 3.1449999809265137 ]
-[ -3.1449999809265137 ]
-[ 3.4500000476837158 ]
-[ 0.34150001406669617 ]
+[ 3.145 ]
+[ -3.145 ]
+[ 3.45 ]
+[ 0.3415 ]
+[ 3.145 ]
+[ -3.145 ]
+[ 3.45 ]
+[ 0.3415 ]
 
 # 16:38:20 >  
 # 16:38:20 >  Done.
diff --git a/monetdb5/mal/Tests/tst045.stable.out 
b/monetdb5/mal/Tests/tst045.stable.out
--- a/monetdb5/mal/Tests/tst045.stable.out
+++ b/monetdb5/mal/Tests/tst045.stable.out
@@ -24,7 +24,7 @@ function user.dummy():void;
 end user.dummy;
 function user.main():void;
 # test variable scope resolution 
-    pi := 3.14700007:flt;
+    pi := 3.147:flt;
 end user.main;
 
 # 07:58:45 >  
diff --git a/monetdb5/mal/Tests/tst048.stable.out 
b/monetdb5/mal/Tests/tst048.stable.out
--- a/monetdb5/mal/Tests/tst048.stable.out
+++ b/monetdb5/mal/Tests/tst048.stable.out
@@ -42,12 +42,12 @@ function user.main():void;
     bat.append(a,2);
     io.print(a);
     b := bat.new(:oid,:flt);
-    bat.append(b,0.300000012);
-    bat.append(b,1.39999998);
+    bat.append(b,0.3);
+    bat.append(b,1.4);
     bat.append(b,2.5);
     io.print(b);
-## c should be of type [:oid, :flt], but it was printed as [:oid, :int] 
-    c := algebra.project(a,2.0999999);
+# c should be of type [:oid, :flt], but it was printed as [:oid, :int] 
+    c := algebra.project(a,2.1);
     io.print(c);
     e := algebra.project(b,2.5);
     io.print(e);
@@ -63,19 +63,19 @@ end user.main;
 [ 2@0,   2       ]
 #-------------------------#
 # h    t                 # name
-# oid  flt               # type
-#-------------------------#
-[ 0@0,   0.300000012     ]
-[ 1@0,   1.39999998      ]
+# void flt  # type
+#--------------------------#
+[ 0@0, 0.3  ]
+[ 1@0, 1.4  ]
 [ 2@0,   2.5             ]
 #-------------------------#
 # h    t                 # name
 # void flt               # type
-#-------------------------#
-[ 0@0,   2.0999999       ]
-[ 1@0,   2.0999999       ]
-[ 2@0,   2.0999999       ]
-#-----------------#
+#--------------------------#
+[ 0@0, 2.1  ]
+[ 1@0, 2.1  ]
+[ 2@0, 2.1  ]
+#--------------------------#
 # h    t         # name
 # void flt       # type
 #-----------------#
diff --git a/monetdb5/mal/Tests/tst061.stable.out 
b/monetdb5/mal/Tests/tst061.stable.out
--- a/monetdb5/mal/Tests/tst061.stable.out
+++ b/monetdb5/mal/Tests/tst061.stable.out
@@ -34,7 +34,7 @@ function user.main():void;
     os := calc.str(o);
     i := calc.sht(1);
     l := calc.lng(2);
-    f := calc.flt(3.4000001);
+    f := calc.flt(3.4);
     j := calc.sht("1");
     d0 := calc.dbl(1);
     d1 := calc.dbl(2);
diff --git a/monetdb5/mal/Tests/tst100.stable.out 
b/monetdb5/mal/Tests/tst100.stable.out
--- a/monetdb5/mal/Tests/tst100.stable.out
+++ b/monetdb5/mal/Tests/tst100.stable.out
@@ -24,7 +24,7 @@ function user.main():void;
 # complex first test, can we gain access to the calculator function 
     a := calc.+(3,1);
     c := calc.+(7,8);
-    b := calc.+(3.5,2.70000005);
+    b := calc.+(3.5,2.7);
     s := "hello world";
     d := calc.+(3,1);
 end user.main;
diff --git a/monetdb5/mal/Tests/tst101.stable.out 
b/monetdb5/mal/Tests/tst101.stable.out
--- a/monetdb5/mal/Tests/tst101.stable.out
+++ b/monetdb5/mal/Tests/tst101.stable.out
@@ -23,7 +23,7 @@ function user.main():void;
 #define the generic addition operator 
 # this should be sufficient to determine outcome 
     a := calc.+(3,1);
-    b := calc.+(3.5,2.70000005);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to