]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make the round() function work correctly on numbers with very large exponents.
authordrh <drh@noemail.net>
Sat, 13 Aug 2005 03:07:47 +0000 (03:07 +0000)
committerdrh <drh@noemail.net>
Sat, 13 Aug 2005 03:07:47 +0000 (03:07 +0000)
Ticket #1340. (CVS 2585)

FossilOrigin-Name: 4f47c3c884e38b810450b6127ab33c7b86e6743c

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

index d44526ad720d1978dd44b265ab4acc1c337cebaf..3bc74a872a5d556eac57e8df3071e726b1230cf3 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\smemory\sleak\sthat\soccurs\swhen\sa\sCREATE\sTABLE\sthat\scontains\sa\nDEFAULT\sVALUE\sfails\sdue\sto\sa\sname\sconflict.\s\sTickets\s#1356\sand\s#1357.\s(CVS\s2584)
-D 2005-08-13T00:56:27
+C Make\sthe\sround()\sfunction\swork\scorrectly\son\snumbers\swith\svery\slarge\sexponents.\nTicket\s#1340.\s(CVS\s2585)
+D 2005-08-13T03:07:47
 F Makefile.in 22ea9c0fe748f591712d8fe3c6d972c6c173a165
 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -40,7 +40,7 @@ F src/date.c 7444b0900a28da77e57e3337a636873cff0ae940
 F src/delete.c be1fc25c9e109cd8cbab42a43ee696263da7c04b
 F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
 F src/expr.c cad7f9197587db4897192cf21a8629b3b102c682
-F src/func.c 2be0799df0c05066a29e589485ebee0b3f756a15
+F src/func.c a90ea5021616b211cb35bd3df3e9cb81dd56e6b7
 F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
 F src/insert.c 484c73bc1309f283a31baa0e114f3ee980536397
@@ -60,7 +60,7 @@ F src/pager.h 0d9153d6269d60d04af3dd84a0cc0a96253cf4a4
 F src/parse.y d57cdd2adc0923762b40314f08683c836a2e0c90
 F src/pragma.c 59ab7073465a11a531af2796e0385727194accb8
 F src/prepare.c fa0f6068d9b8ec6d5c419c65d4d8ff747d49c5c6
-F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357
+F src/printf.c a06d3527c677334a97eaaa1573d0c644c987acf6
 F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
 F src/select.c c611471052773b94af771693686bd5bcdbbb0dba
 F src/shell.c 86c16f0d534aa51cc82cf9f66903d4eb681580e7
@@ -182,7 +182,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 92ba4c510b4fc61120ffa4a01820446ed917ae57
+F test/printf.test 96ae2891aa9e9ad3eba0bd7608ffe536437dd045
 F test/progress.test 16496001da445e6534afb94562c286708316d82f x
 F test/quick.test a94d12658a2b590c1a5be580bef09bbb04c1266b
 F test/quote.test 6d75cf635d93ba2484dc9cb378d88cbae9dc2c62
@@ -291,7 +291,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b
-P d6146a542aacd10d349d432fe343cc17cc3b3ab5
-R 7f8aeeb4ab1fe1e474436a73d25367af
+P 25cfe9390dda79bb2a7740b3d7380f517a4e8d1b
+R c6274d9ed3a9c273a8983dbfcf799ac8
 U drh
-Z 8da5a6f117cbcb4fe1a6bf8af96a2067
+Z 745b1dec57cb9cc3d543dad039e1c761
index 449cf2cb7d778c9f8d6509d06c20bbe7fe9795b7..4a2eac1c4a66afa61dc59c2803c337b303ccf451 100644 (file)
@@ -1 +1 @@
-25cfe9390dda79bb2a7740b3d7380f517a4e8d1b
\ No newline at end of file
+4f47c3c884e38b810450b6127ab33c7b86e6743c
\ No newline at end of file
index 205742a3e87e01f5aa1f53e46823eadca16e4aa8..c58bf21866c9238fb44a8c141c6b639622ee22db 100644 (file)
@@ -16,7 +16,7 @@
 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: func.c,v 1.102 2005/07/09 02:38:06 drh Exp $
+** $Id: func.c,v 1.103 2005/08/13 03:07:47 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -184,7 +184,7 @@ static void substrFunc(
 static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   int n = 0;
   double r;
-  char zBuf[100];
+  char zBuf[500];  /* larger than the %f representation of the largest double */
   assert( argc==1 || argc==2 );
   if( argc==2 ){
     if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
index 6e700771b4ba2e34ef6129d67a1748abc47bde2d..2157ea7efef72cafb3468088484a996bc4f49be6 100644 (file)
@@ -436,6 +436,7 @@ 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<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
index ecaef37fa1748e0e282e08429a88ae17c68463ef..68ef1e637042e156078d131577d699cea7329c00 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.14 2004/09/09 00:35:30 drh Exp $
+# $Id: printf.test,v 1.15 2005/08/13 03:07:47 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -73,7 +73,7 @@ foreach {a b} {1 1 5 5 10 10 10 5} {
   incr m
 }
 
-}
+}  ;# endif not windows
 
 do_test printf-3.1 {
   sqlite3_mprintf_str {A String: (%*.*s)} 10 10 {This is the string}
@@ -174,5 +174,11 @@ do_test printf-10.2 {
   sqlite3_mprintf_stronly %q {}
 } {}
 
+# Ticket #1340:  Test for loss of precision on large positive exponents
+#
+do_test printf-10.3 {
+  sqlite3_mprintf_double {%d %d %f} 1 1 1e300
+} {1 1 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000}
+
 
 finish_test