aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/printf.c6
-rw-r--r--src/test1.c43
2 files changed, 42 insertions, 7 deletions
diff --git a/src/printf.c b/src/printf.c
index d4cb66499..aaf145009 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -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 ){
diff --git a/src/test1.c b/src/test1.c
index cd0c65585..8aafd15ac 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -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
@@ -745,6 +745,40 @@ static int sqlite3_mprintf_stronly(
}
/*
+** 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?
**
** Rig sqliteMalloc() to fail on the N-th call and every REPEAT-INTERVAL call
@@ -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 },