aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshane <shane@noemail.net>2009-02-04 03:59:25 +0000
committershane <shane@noemail.net>2009-02-04 03:59:25 +0000
commitfbd60f826d0276401c6dd3d085ce4ebb7843836e (patch)
treed841324093c9e0c02e0268fcb52baab06a5e48a3 /src
parent63207ab2623be80c0a63c777f71e86d81d732f1d (diff)
downloadsqlite-fbd60f826d0276401c6dd3d085ce4ebb7843836e.tar.gz
sqlite-fbd60f826d0276401c6dd3d085ce4ebb7843836e.zip
Changes to completely remove all floating point ops if SQLITE_OMIT_FLOATING_POINT defined. Note that w/o fp, date/time, round, nan, etc. are all gone or limited in functionality. Updated some of the test scripts to support missing fp and 64-bit functionality. Ticket #3029. (CVS 6250)
FossilOrigin-Name: 5cef400023205b55152b91441acc78f9cd8d58a9
Diffstat (limited to 'src')
-rw-r--r--src/date.c12
-rw-r--r--src/expr.c12
-rw-r--r--src/func.c9
-rw-r--r--src/main.c4
-rw-r--r--src/os_win.c29
-rw-r--r--src/util.c3
-rw-r--r--src/vdbe.c7
-rw-r--r--src/vdbeapi.c5
-rw-r--r--src/vdbemem.c14
-rw-r--r--src/where.c17
10 files changed, 77 insertions, 35 deletions
diff --git a/src/date.c b/src/date.c
index c8aeceffb..0fa1ee98d 100644
--- a/src/date.c
+++ b/src/date.c
@@ -16,7 +16,7 @@
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: date.c,v 1.102 2009/01/30 17:27:44 drh Exp $
+** $Id: date.c,v 1.103 2009/02/04 03:59:25 shane Exp $
**
** SQLite processes all times and dates as Julian Day numbers. The
** dates and times are stored as the number of days since noon
@@ -1042,9 +1042,19 @@ static void currentTimeFunc(
double rT;
char zBuf[20];
+ UNUSED_PARAMETER(argc);
+ UNUSED_PARAMETER(argv);
+
db = sqlite3_context_db_handle(context);
sqlite3OsCurrentTime(db->pVfs, &rT);
+#ifndef SQLITE_OMIT_FLOATING_POINT
t = 86400.0*(rT - 2440587.5) + 0.5;
+#else
+ /* without floating point support, rT will have
+ ** already lost fractional day precision.
+ */
+ t = 86400 * (rT - 2440587) - 43200;
+#endif
#ifdef HAVE_GMTIME_R
{
struct tm sNow;
diff --git a/src/expr.c b/src/expr.c
index 746b598a8..8960a7ad9 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
-** $Id: expr.c,v 1.410 2009/01/20 16:53:40 danielk1977 Exp $
+** $Id: expr.c,v 1.411 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
@@ -1932,12 +1932,10 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
case TK_UMINUS: {
Expr *pLeft = pExpr->pLeft;
assert( pLeft );
- if( pLeft->op==TK_FLOAT || pLeft->op==TK_INTEGER ){
- if( pLeft->op==TK_FLOAT ){
- codeReal(v, (char*)pLeft->token.z, pLeft->token.n, 1, target);
- }else{
- codeInteger(v, pLeft, 1, target);
- }
+ if( pLeft->op==TK_FLOAT ){
+ codeReal(v, (char*)pLeft->token.z, pLeft->token.n, 1, target);
+ }else if( pLeft->op==TK_INTEGER ){
+ codeInteger(v, pLeft, 1, target);
}else{
regFree1 = r1 = sqlite3GetTempReg(pParse);
sqlite3VdbeAddOp2(v, OP_Integer, 0, r1);
diff --git a/src/func.c b/src/func.c
index 85af9e0e9..07671ff6b 100644
--- a/src/func.c
+++ b/src/func.c
@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: func.c,v 1.221 2009/02/03 15:50:34 drh Exp $
+** $Id: func.c,v 1.222 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
@@ -243,6 +243,7 @@ static void substrFunc(
/*
** Implementation of the round() function
*/
+#ifndef SQLITE_OMIT_FLOATING_POINT
static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
int n = 0;
double r;
@@ -260,6 +261,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
sqlite3AtoF(zBuf, &r);
sqlite3_result_double(context, r);
}
+#endif
/*
** Allocate nByte bytes of space using sqlite3_malloc(). If the
@@ -1131,7 +1133,8 @@ static void avgFinalize(sqlite3_context *context){
static void totalFinalize(sqlite3_context *context){
SumCtx *p;
p = sqlite3_aggregate_context(context, 0);
- sqlite3_result_double(context, p ? p->rSum : 0.0);
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
+ sqlite3_result_double(context, p ? p->rSum : (double)0);
}
/*
@@ -1378,8 +1381,10 @@ void sqlite3RegisterGlobalFunctions(void){
FUNCTION(substr, 2, 0, 0, substrFunc ),
FUNCTION(substr, 3, 0, 0, substrFunc ),
FUNCTION(abs, 1, 0, 0, absFunc ),
+#ifndef SQLITE_OMIT_FLOATING_POINT
FUNCTION(round, 1, 0, 0, roundFunc ),
FUNCTION(round, 2, 0, 0, roundFunc ),
+#endif
FUNCTION(upper, 1, 0, 0, upperFunc ),
FUNCTION(lower, 1, 0, 0, lowerFunc ),
FUNCTION(coalesce, 1, 0, 0, 0 ),
diff --git a/src/main.c b/src/main.c
index 58f5443ca..31acd559f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: main.c,v 1.525 2009/02/03 16:51:25 danielk1977 Exp $
+** $Id: main.c,v 1.526 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
@@ -191,6 +191,7 @@ int sqlite3_initialize(void){
** reason. So we run it once during initialization.
*/
#ifndef NDEBUG
+#ifndef SQLITE_OMIT_FLOATING_POINT
/* This section of code's only "output" is via assert() statements. */
if ( rc==SQLITE_OK ){
u64 x = (((u64)1)<<63)-1;
@@ -201,6 +202,7 @@ int sqlite3_initialize(void){
assert( sqlite3IsNaN(y) );
}
#endif
+#endif
return rc;
}
diff --git a/src/os_win.c b/src/os_win.c
index 636e9e686..02f4f7333 100644
--- a/src/os_win.c
+++ b/src/os_win.c
@@ -12,7 +12,7 @@
**
** This file contains code that is specific to windows.
**
-** $Id: os_win.c,v 1.146 2009/01/30 05:59:11 shane Exp $
+** $Id: os_win.c,v 1.147 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_WIN /* This file is used for windows only */
@@ -755,10 +755,10 @@ int sqlite3_fullsync_count = 0;
static int winSync(sqlite3_file *id, int flags){
#ifndef SQLITE_NO_SYNC
winFile *pFile = (winFile*)id;
+ OSTRACE3("SYNC %d lock=%d\n", pFile->h, pFile->locktype);
#else
UNUSED_PARAMETER(id);
#endif
- OSTRACE3("SYNC %d lock=%d\n", pFile->h, pFile->locktype);
#ifndef SQLITE_TEST
UNUSED_PARAMETER(flags);
#else
@@ -1672,7 +1672,7 @@ int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
/* FILETIME structure is a 64-bit value representing the number of
100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
*/
- double now;
+ sqlite3_int64 timeW, timeF;
#if SQLITE_OS_WINCE
SYSTEMTIME time;
GetSystemTime(&time);
@@ -1684,11 +1684,28 @@ int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
GetSystemTimeAsFileTime( &ft );
#endif
UNUSED_PARAMETER(pVfs);
- now = ((double)ft.dwHighDateTime) * 4294967296.0;
- *prNow = (now + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
+#if defined(_MSC_VER)
+ timeW = (((sqlite3_int64)ft.dwHighDateTime)*4294967296) + ft.dwLowDateTime;
+ timeF = timeW % 864000000000; /* fractional days (100-nanoseconds) */
+ timeW = timeW / 864000000000; /* whole days */
+ timeW = timeW + 2305813; /* add whole days (from 2305813.5) */
+ timeF = timeF + 432000000000; /* add half a day (from 2305813.5) */
+ timeW = timeW + (timeF / 864000000000); /* add whole day if half day made one */
+ timeF = timeF % 864000000000; /* compute new fractional days */
+ *prNow = (double)timeW + ((double)timeF / (double)864000000000);
+#else
+ timeW = (((sqlite3_int64)ft.dwHighDateTime)*4294967296LL) + ft.dwLowDateTime;
+ timeF = timeW % 864000000000LL; /* fractional days (100-nanoseconds) */
+ timeW = timeW / 864000000000LL; /* whole days */
+ timeW = timeW + 2305813; /* add whole days (from 2305813.5) */
+ timeF = timeF + 432000000000LL; /* add half a day (from 2305813.5) */
+ timeW = timeW + (timeF / 864000000000LL); /* add whole day if half day made one */
+ timeF = timeF % 864000000000LL; /* compute new fractional days */
+ *prNow = (double)timeW + ((double)timeF / (double)864000000000LL);
+#endif
#ifdef SQLITE_TEST
if( sqlite3_current_time ){
- *prNow = sqlite3_current_time/86400.0 + 2440587.5;
+ *prNow = ((double)sqlite3_current_time + (double)43200) / (double)86400 + (double)2440587;
}
#endif
return 0;
diff --git a/src/util.c b/src/util.c
index 4eb01b0da..829dfe847 100644
--- a/src/util.c
+++ b/src/util.c
@@ -14,12 +14,11 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.247 2009/01/20 16:53:41 danielk1977 Exp $
+** $Id: util.c,v 1.248 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
-
/*
** Routine needed to support the testcase() macro.
*/
diff --git a/src/vdbe.c b/src/vdbe.c
index b6da22237..1028e8163 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
-** $Id: vdbe.c,v 1.813 2009/02/01 00:29:57 drh Exp $
+** $Id: vdbe.c,v 1.814 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -1228,7 +1228,8 @@ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
case OP_Subtract: b -= a; break;
case OP_Multiply: b *= a; break;
case OP_Divide: {
- if( a==0.0 ) goto arithmetic_result_is_null;
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
+ if( a==(double)0 ) goto arithmetic_result_is_null;
b /= a;
break;
}
@@ -1873,7 +1874,7 @@ case OP_IfNot: { /* jump, in1 */
c = pOp->p3;
}else{
#ifdef SQLITE_OMIT_FLOATING_POINT
- c = sqlite3VdbeIntValue(pIn1);
+ c = sqlite3VdbeIntValue(pIn1)!=0;
#else
c = sqlite3VdbeRealValue(pIn1)!=0.0;
#endif
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 8f3c2b388..d3274b540 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -13,7 +13,7 @@
** This file contains code use to implement APIs that are part of the
** VDBE.
**
-** $Id: vdbeapi.c,v 1.150 2008/12/10 18:03:47 drh Exp $
+** $Id: vdbeapi.c,v 1.151 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -752,7 +752,8 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){
vals = sqlite3_data_count(pStmt);
pOut = &pVm->pResultSet[i];
}else{
- static const Mem nullMem = {{0}, 0.0, 0, "", 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
+ /* ((double)0) In case of SQLITE_OMIT_FLOATING_POINT... */
+ static const Mem nullMem = {{0}, (double)0, 0, "", 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
if( pVm->db ){
sqlite3_mutex_enter(pVm->db->mutex);
sqlite3Error(pVm->db, SQLITE_RANGE, 0);
diff --git a/src/vdbemem.c b/src/vdbemem.c
index bd103245e..cc1ffc282 100644
--- a/src/vdbemem.c
+++ b/src/vdbemem.c
@@ -15,7 +15,7 @@
** only within the VDBE. Interface routines refer to a Mem using the
** name sqlite_value
**
-** $Id: vdbemem.c,v 1.136 2009/02/03 15:39:01 drh Exp $
+** $Id: vdbemem.c,v 1.137 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -373,17 +373,20 @@ double sqlite3VdbeRealValue(Mem *pMem){
}else if( pMem->flags & MEM_Int ){
return (double)pMem->u.i;
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
- double val = 0.0;
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
+ double val = (double)0;
pMem->flags |= MEM_Str;
if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
|| sqlite3VdbeMemNulTerminate(pMem) ){
- return 0.0;
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
+ return (double)0;
}
assert( pMem->z );
sqlite3AtoF(pMem->z, &val);
return val;
}else{
- return 0.0;
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
+ return (double)0;
}
}
@@ -969,7 +972,8 @@ int sqlite3ValueFromExpr(
}else if( op==TK_UMINUS ) {
if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
pVal->u.i = -1 * pVal->u.i;
- pVal->r = -1.0 * pVal->r;
+ /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
+ pVal->r = (double)-1 * pVal->r;
}
}
#ifndef SQLITE_OMIT_BLOB_LITERAL
diff --git a/src/where.c b/src/where.c
index 5f10b81b0..89e3f31e9 100644
--- a/src/where.c
+++ b/src/where.c
@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
-** $Id: where.c,v 1.367 2009/02/04 01:49:30 shane Exp $
+** $Id: where.c,v 1.368 2009/02/04 03:59:25 shane Exp $
*/
#include "sqliteInt.h"
@@ -1547,7 +1547,8 @@ static double bestVirtualIndex(
+ sizeof(*pIdxOrderBy)*nOrderBy );
if( pIdxInfo==0 ){
sqlite3ErrorMsg(pParse, "out of memory");
- return 0.0;
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
+ return (double)0;
}
*ppIdxInfo = pIdxInfo;
@@ -1650,7 +1651,8 @@ static double bestVirtualIndex(
pIdxInfo->idxNum = 0;
pIdxInfo->needToFreeIdxStr = 0;
pIdxInfo->orderByConsumed = 0;
- pIdxInfo->estimatedCost = SQLITE_BIG_DBL / 2.0;
+ /* ((double)2) In case of SQLITE_OMIT_FLOATING_POINT... */
+ pIdxInfo->estimatedCost = SQLITE_BIG_DBL / ((double)2);
nOrderBy = pIdxInfo->nOrderBy;
if( pIdxInfo->nOrderBy && !orderByUsable ){
*(int*)&pIdxInfo->nOrderBy = 0;
@@ -1679,7 +1681,8 @@ static double bestVirtualIndex(
if( !pIdxInfo->aConstraint[i].usable && pUsage[i].argvIndex>0 ){
sqlite3ErrorMsg(pParse,
"table %s: xBestIndex returned an invalid plan", pTab->zName);
- return 0.0;
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
+ return (double)0;
}
}
@@ -3092,12 +3095,14 @@ WhereInfo *sqlite3WhereBegin(
sCost.plan.wsFlags = WHERE_VIRTUALTABLE | WHERE_ORDERBY;
}
sCost.plan.nEq = 0;
- if( (SQLITE_BIG_DBL/2.0)<sCost.rCost ){
+ /* (double)2 In case of SQLITE_OMIT_FLOATING_POINT... */
+ if( (SQLITE_BIG_DBL/((double)2))<sCost.rCost ){
/* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
** inital value of lowestCost in this loop. If it is, then
** the (cost<lowestCost) test below will never be true.
*/
- sCost.rCost = (SQLITE_BIG_DBL/2.0);
+ /* (double)2 In case of SQLITE_OMIT_FLOATING_POINT... */
+ sCost.rCost = (SQLITE_BIG_DBL/((double)2));
}
}else
#endif