better handling of exponential notation (CVS 145)
FossilOrigin-Name: ea0e32828f5643eeb00b216a287d14f4826ddf2d
This commit is contained in:
parent
e09efa30c4
commit
a5c2ad06e6
20
manifest
20
manifest
@ -1,9 +1,9 @@
|
||||
C Version\s1.0.4\s(CVS\s496)
|
||||
D 2000-08-28T16:25:00
|
||||
C better\shandling\sof\sexponential\snotation\s(CVS\s145)
|
||||
D 2000-09-14T01:21:10
|
||||
F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
|
||||
F Makefile.in 036bce328b963f48dbaadbec8cc4144a1fd9e50a
|
||||
F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
|
||||
F VERSION a13d4e1d1641b231b44592642d25363ccc2cbb05
|
||||
F VERSION 4edef6ec60a55c61b01fc0abebbf5a2f67c4f0e7
|
||||
F configure 078a370347baf9375baa8053857ca1e6bc84afa7 x
|
||||
F configure.in 381aeb4564f1562b7b2a115f5e99035c561a7fea
|
||||
F doc/lemon.html e233a3e97a779c7a87e1bc4528c664a58e49dd47
|
||||
@ -23,15 +23,15 @@ F src/sqliteInt.h b65fdecac7281aafb4c9ff3e79ea1b5546478385
|
||||
F src/tclsqlite.c 89dc4ba2b521f3e919d6d7aaa4cc1c2aba8e16f3
|
||||
F src/tokenize.c 097bec5843d4a0fb4509e036fee93bac080c5e73
|
||||
F src/update.c 51b9ef7434b15e31096155da920302e9db0d27fc
|
||||
F src/util.c b75b33e6bd5d47898bb7ed9fdd0dea4fe7c19b00
|
||||
F src/vdbe.c 4dd50dbbfb753bae763f0e4eb21b1d17f5cc1423
|
||||
F src/util.c 782f87af3c48c898631a2d5b7074437c899f6f13
|
||||
F src/vdbe.c c0e3d29d2e13997d5664ade19ff2c8e2212945e3
|
||||
F src/vdbe.h 6413cd0165ac62b0839fe3e077cb7c9f0b736295
|
||||
F src/where.c 3dfad2ffd0aa994d5eceac88852f7189c8d1d3c8
|
||||
F test/all.test 0950c135cab7e60c07bd745ccfad1476211e5bd7
|
||||
F test/copy.test b77a1214bd7756f2849d5c4fa6e715c0ff0c34eb
|
||||
F test/dbbe.test c6079572516aeb2739a35fd272b105c45c30cc76
|
||||
F test/delete.test 402ee3ccb6e544582d24c573ef70b34d09583ae7
|
||||
F test/expr.test 09b55ccf81cb8cc2f9cd83d592a2ba187ee48ba8
|
||||
F test/expr.test 48273bf48a15d226c35829f702af4254c0ff6795
|
||||
F test/func.test 02aed8845b98bde1043dda97455de1d37238ebb3
|
||||
F test/in.test 2c560c0f55fb777029fd9bb5378f2997582aa603
|
||||
F test/index.test 950be6116122c6e2db7c2c345eabcdb854ced1d0
|
||||
@ -62,7 +62,7 @@ F www/arch.fig 4e26e9dca3c49724fc8f554c695ddea9f2413156
|
||||
F www/arch.png c4d908b79065a72e7dcf19317f36d1324c550e87
|
||||
F www/arch.tcl 4f6a9afecc099a27bba17b4f8cc9561abc15dc40
|
||||
F www/c_interface.tcl 1b79e404a0dd46f44cd453a44b01df568c9586d1
|
||||
F www/changes.tcl 3f58bd3095d46f73f5b04f4584aa9a628586cdaf
|
||||
F www/changes.tcl 8ac23210e8cef43b77041f01b439a6ff3d1554fc
|
||||
F www/crosscompile.tcl 19734ce7f18b16ff2ed8479412abf8aca56e1dcc
|
||||
F www/fileformat.tcl cfb7fba80b7275555281ba2f256c00734bcdd1c9
|
||||
F www/index.tcl 2f5cc070b8fa8c3fc2f71bba4e6b7877d528fbde
|
||||
@ -71,7 +71,7 @@ F www/mingw.tcl fc5f4ba9d336b6e8c97347cc6496d6162461ef60
|
||||
F www/opcode.tcl cb3a1abf8b7b9be9f3a228d097d6bf8b742c2b6f
|
||||
F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f
|
||||
F www/vdbe.tcl bcbfc33bcdd0ebad95eab31286adb9e1bc289520
|
||||
P b8cec9b938b4be1ccf230588d8e1564fb3ac4316
|
||||
R b19d9376e2ed736a8c71d021909787e7
|
||||
P 92346e003eba759251d23c296f97a7ad6299f5de
|
||||
R d838e77add09f4d92cf328c578007f7b
|
||||
U drh
|
||||
Z 240a9899293f42faa04a2a025b9382ba
|
||||
Z 003a64f816759573cb4ebb770e70d29a
|
||||
|
@ -1 +1 @@
|
||||
92346e003eba759251d23c296f97a7ad6299f5de
|
||||
ea0e32828f5643eeb00b216a287d14f4826ddf2d
|
83
src/util.c
83
src/util.c
@ -26,7 +26,7 @@
|
||||
** This file contains functions for allocating memory, comparing
|
||||
** strings, and stuff like that.
|
||||
**
|
||||
** $Id: util.c,v 1.14 2000/07/31 11:57:37 drh Exp $
|
||||
** $Id: util.c,v 1.15 2000/09/14 01:21:10 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
@ -550,6 +550,41 @@ static int privateStrCmp(const char *atext, const char *btext, int useCase){
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
** Do a comparison of pure numerics. If either string is not a pure
|
||||
** numeric, then return 0. Otherwise return 1 and set *pResult to be
|
||||
** negative, zero or positive if the first string are numerially less than
|
||||
** equal to, or greater than the second.
|
||||
*/
|
||||
static int privateCompareNum(const char *a, const char *b, int *pResult){
|
||||
char *endPtr;
|
||||
double rA, rB;
|
||||
int isNumA, isNumB;
|
||||
if( isdigit(*a) || ((*a=='-' || *a=='+') && isdigit(a[1])) ){
|
||||
rA = strtod(a, &endPtr);
|
||||
isNumA = *endPtr==0;
|
||||
}else{
|
||||
isNumA = 0;
|
||||
}
|
||||
if( isdigit(*b) || ((*b=='-' || *b=='+') && isdigit(b[1])) ){
|
||||
rB = strtod(b, &endPtr);
|
||||
isNumB = *endPtr==0;
|
||||
}else{
|
||||
isNumB = 0;
|
||||
}
|
||||
if( isNumB==0 && isNumA==0 ) return 0;
|
||||
if( isNumA!=isNumB ){
|
||||
*pResult = isNumA - isNumB;
|
||||
}else if( rA<rB ){
|
||||
*pResult = -1;
|
||||
}else if( rA>rB ){
|
||||
*pResult = 1;
|
||||
}else{
|
||||
*pResult = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* This comparison routine is what we use for comparison operations
|
||||
** in an SQL expression. (Ex: name<'Hello' or value<5). Compare two
|
||||
** strings. Use case only as a tie-breaker. Numbers compare in
|
||||
@ -557,8 +592,10 @@ static int privateStrCmp(const char *atext, const char *btext, int useCase){
|
||||
*/
|
||||
int sqliteCompare(const char *atext, const char *btext){
|
||||
int result;
|
||||
result = privateStrCmp(atext, btext, 0);
|
||||
if( result==0 ) result = privateStrCmp(atext, btext, 1);
|
||||
if( !privateCompareNum(atext, btext, &result) || result==0 ){
|
||||
result = privateStrCmp(atext, btext, 0);
|
||||
if( result==0 ) result = privateStrCmp(atext, btext, 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -573,12 +610,13 @@ int sortCmp(const char **a, const char **b){
|
||||
return sqliteCompare(*a, *b);
|
||||
}
|
||||
int main(int argc, char **argv){
|
||||
int i, j, k, n;
|
||||
int i, j, k, n, cnt;
|
||||
static char *azStr[] = {
|
||||
"abc", "aBc", "abcd", "aBcd",
|
||||
"123", "124", "1234", "-123", "-124", "-1234",
|
||||
"123", "124", "1234", "-123", "-124", "-1234", "+124",
|
||||
"123.45", "123.456", "123.46", "-123.45", "-123.46", "-123.456",
|
||||
"x9", "x10", "x-9", "x-10", "X9", "X10",
|
||||
"1.234e+02", "+123", "1.23E2", "1.2345e+2", "-1.2345e2", "+w"
|
||||
};
|
||||
n = sizeof(azStr)/sizeof(azStr[0]);
|
||||
qsort(azStr, n, sizeof(azStr[0]), sortCmp);
|
||||
@ -587,6 +625,7 @@ int main(int argc, char **argv){
|
||||
}
|
||||
printf("Sanity1...");
|
||||
fflush(stdout);
|
||||
cnt = 0;
|
||||
for(i=0; i<n-1; i++){
|
||||
char *a = azStr[i];
|
||||
for(j=i+1; j<n; j++){
|
||||
@ -595,10 +634,42 @@ int main(int argc, char **argv){
|
||||
printf("Failed! \"%s\" vs \"%s\"\n", a, b);
|
||||
i = j = n;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
if( i<n ){
|
||||
printf(" OK\n");
|
||||
printf(" OK (%d)\n", cnt);
|
||||
}
|
||||
printf("Sanity2...");
|
||||
fflush(stdout);
|
||||
cnt = 0;
|
||||
for(i=0; i<n; i++){
|
||||
char *a = azStr[i];
|
||||
for(j=0; j<n; j++){
|
||||
char *b = azStr[j];
|
||||
for(k=0; k<n; k++){
|
||||
char *c = azStr[k];
|
||||
int x1, x2, x3, success;
|
||||
x1 = sqliteCompare(a,b);
|
||||
x2 = sqliteCompare(b,c);
|
||||
x3 = sqliteCompare(a,c);
|
||||
if( x1==0 ){
|
||||
success = x2==x3;
|
||||
}else if( x1<0 ){
|
||||
success = (x2<=0 && x3<=0) || x2>0;
|
||||
}else{
|
||||
success = (x2>=0 && x3>=0) || x2<0;
|
||||
}
|
||||
if( !success ){
|
||||
printf("Failed! \"%s\" vs \"%s\" vs \"%s\"\n", a, b, c);
|
||||
i = j = k = n+1;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( i<n+1 ){
|
||||
printf(" OK (%d)\n", cnt);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@
|
||||
** But other routines are also provided to help in building up
|
||||
** a program instruction by instruction.
|
||||
**
|
||||
** $Id: vdbe.c,v 1.40 2000/08/28 16:22:00 drh Exp $
|
||||
** $Id: vdbe.c,v 1.41 2000/09/14 01:21:10 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <unistd.h>
|
||||
@ -547,7 +547,7 @@ static int hardStringify(Vdbe *p, int i){
|
||||
char zBuf[30];
|
||||
int fg = p->aStack[i].flags;
|
||||
if( fg & STK_Real ){
|
||||
sprintf(zBuf,"%g",p->aStack[i].r);
|
||||
sprintf(zBuf,"%.15g",p->aStack[i].r);
|
||||
}else if( fg & STK_Int ){
|
||||
sprintf(zBuf,"%d",p->aStack[i].i);
|
||||
}else{
|
||||
|
@ -23,7 +23,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing expressions.
|
||||
#
|
||||
# $Id: expr.test,v 1.8 2000/06/16 20:51:26 drh Exp $
|
||||
# $Id: expr.test,v 1.9 2000/09/14 01:21:11 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -80,8 +80,8 @@ test_expr expr-1.37 {i1=1, i2=NULL} {not i2} {1}
|
||||
test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57
|
||||
test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11
|
||||
test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782
|
||||
test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641
|
||||
test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90244
|
||||
test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641025641026
|
||||
test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90243902439024
|
||||
test_expr expr-2.6 {r1=1.23, r2=2.34} {r2<r1} 0
|
||||
test_expr expr-2.7 {r1=1.23, r2=2.34} {r2<=r1} 0
|
||||
test_expr expr-2.8 {r1=1.23, r2=2.34} {r2>r1} 1
|
||||
|
@ -17,6 +17,13 @@ proc chng {date desc} {
|
||||
puts "<DD><P><UL>$desc</UL></P></DD>"
|
||||
}
|
||||
|
||||
chng {2000 Sep 13 (Version 1.0.5)} {
|
||||
<li>Changed the print format for floating point values from "%g" to "%.15g".
|
||||
</li>
|
||||
<li>Changed the comparison function so that numbers in exponential notation
|
||||
(ex: 1.234e+05) sort in numerical order.</li>
|
||||
}
|
||||
|
||||
chng {2000 Aug 28 (Version 1.0.4)} {
|
||||
<li>Added functions <b>length()</b> and <b>substr()</b>.</li>
|
||||
<li>Fix a bug in the <b>sqlite</b> shell program that was causing
|
||||
|
Loading…
Reference in New Issue
Block a user