]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix printf.c so that it handles 10.0 correctly. (CVS 2643)
authordrh <drh@noemail.net>
Tue, 30 Aug 2005 19:30:59 +0000 (19:30 +0000)
committerdrh <drh@noemail.net>
Tue, 30 Aug 2005 19:30:59 +0000 (19:30 +0000)
FossilOrigin-Name: 0f7a53f78d9dd5c426be834f2d50a6fe4e860141

manifest
manifest.uuid
src/printf.c
src/test1.c
test/printf.test

index 0cd2efa839c29e2ed5c193270d522c8f0b25a368..951c617290386edef9463d6b07a1d605110ae27c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Minor\scode\senhancements.\s(CVS\s2642)
-D 2005-08-30T00:54:02
+C Fix\sprintf.c\sso\sthat\sit\shandles\s10.0\scorrectly.\s(CVS\s2643)
+D 2005-08-30T19:30:59
 F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -61,7 +61,7 @@ F src/pager.h 17b13225abd93c1e9f470060f40a21b9edb5a164
 F src/parse.y d57cdd2adc0923762b40314f08683c836a2e0c90
 F src/pragma.c 69413fbdc0c6aaa493a776ea52c1b3e6cf35dfb2
 F src/prepare.c 86f0d8e744b8d956eff6bc40e29049efee017610
-F src/printf.c cea584c5888688c650d856563aadc4296b5afac7
+F src/printf.c d2678b06cfa07be9b14c330a42310f62340e34ce
 F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
 F src/select.c a185b91fd0060a16ada1a32de844d8e570273070
 F src/shell.c d2d4ef04732c28a84d108b8413cd4e584754a158
@@ -69,7 +69,7 @@ F src/sqlite.h.in d6561d51025d08de4f455607f3f9f9aa76e855d5
 F src/sqliteInt.h 207b63f9782d7faf1f19e694e8052e60841fb377
 F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
 F src/tclsqlite.c ac94682f9e601dd373912c46414a5a842db2089a
-F src/test1.c 810b7563b03efc797f350e9370955120e7072c6f
+F src/test1.c 97425910c6adf87b5dc867ae7704f0430441663c
 F src/test2.c 792f203be69fea88668fa221321194f0a28dfdfa
 F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7
 F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
@@ -188,7 +188,7 @@ F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e
 F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
 F test/pagesize.test cbc6a312b6f6c0f02619b189985df2a14164b690
 F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b
-F test/printf.test 4a91651d4fd5eea999eee82a9bdd0a1b797b9ad9
+F test/printf.test f527c840b75734d6560fb9d7ae635d14637b05a7
 F test/progress.test 16496001da445e6534afb94562c286708316d82f x
 F test/quick.test a94d12658a2b590c1a5be580bef09bbb04c1266b
 F test/quote.test c1ca5e18800455f1c882baf5b0274755a3836549
@@ -299,7 +299,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 0e1ac1284c0547af0bb0eb4ff320b9f5ae9c248d
-R baaeb5d73948ab9b678cf5ec65e8b13b
+P 4ab994a87ee844f453d693555abd61b51bb44a0e
+R 106c16c92c68a4e3427edf7e39ce8d68
 U drh
-Z 677bb92f950696e8a5b8946d54c8a93f
+Z 17516a59ec1ecb81c51ea80b9861d229
index 2ed8191d7942038e9a04391c0a055b9155b42dd6..1bd6ebd00a9806192ad1aa2f4e63aa7f792245f8 100644 (file)
@@ -1 +1 @@
-4ab994a87ee844f453d693555abd61b51bb44a0e
\ No newline at end of file
+0f7a53f78d9dd5c426be834f2d50a6fe4e860141
\ No newline at end of file
index d4cb66499fb57ccd827c446ac579a1d95dab04da..aaf1450096bd559fd8e7e71267ffce1019fb6717 100644 (file)
@@ -440,9 +440,9 @@ static int vxprintf(
         /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
         exp = 0;
         if( realvalue>0.0 ){
-          while( realvalue>1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
-          while( realvalue>1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
-          while( realvalue>10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
+          while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
+          while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
+          while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
           while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
           while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
           if( exp>350 || exp<-350 ){
index cd0c65585cf15958c18da4a2e6f298041fae6162..8aafd15ac2070387ff47a03a1a90816c4e9fa719 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test1.c,v 1.156 2005/08/29 23:00:05 drh Exp $
+** $Id: test1.c,v 1.157 2005/08/30 19:30:59 drh Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -661,7 +661,7 @@ static int sqlite3_mprintf_str(
 }
 
 /*
-** Usage:  sqlite3_mprintf_str FORMAT INTEGER INTEGER DOUBLE
+** Usage:  sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE
 **
 ** Call mprintf with two integer arguments and one double argument
 */
@@ -676,7 +676,7 @@ static int sqlite3_mprintf_double(
   char *z;
   if( argc!=5 ){
     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
-       " FORMAT INT INT STRING\"", 0);
+       " FORMAT INT INT DOUBLE\"", 0);
     return TCL_ERROR;
   }
   for(i=2; i<4; i++){
@@ -690,7 +690,7 @@ static int sqlite3_mprintf_double(
 }
 
 /*
-** Usage:  sqlite3_mprintf_str FORMAT DOUBLE DOUBLE
+** Usage:  sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE
 **
 ** Call mprintf with a single double argument which is the product of the
 ** two arguments given above.  This is used to generate overflow and underflow
@@ -744,6 +744,40 @@ static int sqlite3_mprintf_stronly(
   return TCL_OK;
 }
 
+/*
+** Usage:  sqlite3_mprintf_hexdouble FORMAT HEX
+**
+** Call mprintf with a single double argument which is derived from the
+** hexadecimal encoding of an IEEE double.
+*/
+static int sqlite3_mprintf_hexdouble(
+  void *NotUsed,
+  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
+  int argc,              /* Number of arguments */
+  char **argv            /* Text of each argument */
+){
+  char *z;
+  double r;
+  unsigned  x1, x2;
+  long long unsigned d;
+  if( argc!=3 ){
+    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
+       " FORMAT STRING\"", 0);
+    return TCL_ERROR;
+  }
+  if( sscanf(argv[2], "%08x%08x", &x2, &x1)!=2 ){
+    Tcl_AppendResult(interp, "2nd argument should be 16-characters of hex", 0);
+    return TCL_ERROR;
+  }
+  d = x2;
+  d = (d<<32) + x1;
+  memcpy(&r, &d, sizeof(r));
+  z = sqlite3_mprintf(argv[1], r);
+  Tcl_AppendResult(interp, z, 0);
+  sqlite3_free(z);
+  return TCL_OK;
+}
+
 /*
 ** Usage: sqlite_malloc_fail N  ?REPEAT-INTERVAL?
 **
@@ -3010,6 +3044,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
      { "sqlite3_mprintf_stronly",       (Tcl_CmdProc*)sqlite3_mprintf_stronly},
      { "sqlite3_mprintf_double",        (Tcl_CmdProc*)sqlite3_mprintf_double },
      { "sqlite3_mprintf_scaled",        (Tcl_CmdProc*)sqlite3_mprintf_scaled },
+     { "sqlite3_mprintf_hexdouble",   (Tcl_CmdProc*)sqlite3_mprintf_hexdouble},
      { "sqlite3_mprintf_z_test",        (Tcl_CmdProc*)test_mprintf_z        },
      { "sqlite3_last_insert_rowid",     (Tcl_CmdProc*)test_last_rowid       },
      { "sqlite3_exec_printf",           (Tcl_CmdProc*)test_exec_printf      },
index 5a8b14ba6dc3d7c34e87fa7745925b7a9fa0c765..4dd3b2e7c110e81fc1053ae2757f93c8d2a7cbf7 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the sqlite_*_printf() interface.
 #
-# $Id: printf.test,v 1.17 2005/08/19 02:26:27 drh Exp $
+# $Id: printf.test,v 1.18 2005/08/30 19:30:59 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -219,4 +219,17 @@ do_test printf-12.1 {
   sqlite3_mprintf_double {%d %d %.2000g} 1 1 1.0
 } {1 1 1}
 
+# Floating point boundary cases
+#
+do_test printf-13.1 {
+  sqlite3_mprintf_hexdouble %.20f 4024000000000000
+} {10.00000000000000000000}
+do_test printf-13.2 {
+  sqlite3_mprintf_hexdouble %.20f 4197d78400000000
+} {100000000.00000000000000000000}
+do_test printf-13.3 {
+  sqlite3_mprintf_hexdouble %.20f 4693b8b5b5056e17
+} {100000000000000000000000000000000.00000000000000000000}
+
+
 finish_test