1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Fix printf.c so that it handles 10.0 correctly. (CVS 2643)

FossilOrigin-Name: 0f7a53f78d9dd5c426be834f2d50a6fe4e860141
This commit is contained in:
drh
2005-08-30 19:30:59 +00:00
parent 5d9a4af9af
commit 63782855ee
5 changed files with 65 additions and 17 deletions

View File

@ -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

View File

@ -1 +1 @@
4ab994a87ee844f453d693555abd61b51bb44a0e
0f7a53f78d9dd5c426be834f2d50a6fe4e860141

View 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 ){

View 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 },

View 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