/ Check-in [ca154f97]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Do correct affinity transformations on floating point values which have a decimal point at the beginning or end of the mantissa. Ticket [3998683a16a7076e08f5].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1:ca154f97a590745539b2cbfd77eb319fd7392a40
User & Date: drh 2010-09-30 17:33:12
Context
2010-09-30
18:12
Remove unnecessary calls to memAboutToChange() in vdbe.c. An affinity change no longer invalidates shallow copies. check-in: afb0fd0b user: drh tags: experimental
17:33
Do correct affinity transformations on floating point values which have a decimal point at the beginning or end of the mantissa. Ticket [3998683a16a7076e08f5]. check-in: ca154f97 user: drh tags: experimental
16:51
Changes to remove sqlite3FitsIn64Bits(). check-in: 43fef1ca user: shaneh tags: experimental
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/util.c.

235
236
237
238
239
240
241
242
243
244
245
246
247
248












249
250
251
252
253
254
255
256
257
258
259

260
261


262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318
319
320
321
322

323
324





325
326
327
328
329
330
331
...
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
  b = (unsigned char *)zRight;
  while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
  return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
}

/*
** The string z[] is an text representation of a real number.
** Convert this string to a double.
**
** The string z[] is length bytes in length (bytes, not characters) and
** uses the encoding enc.  The string is not necessarily zero-terminated.
**
** Return TRUE if the result is a valid real number (or integer) and FALSE
** if the string is empty or contains extraneous text.












*/
int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
#ifndef SQLITE_OMIT_FLOATING_POINT
  int incr = (enc==SQLITE_UTF8?1:2);
  const char *zEnd = z + length;
  /* sign * significand * (10 ^ (esign * exponent)) */
  int sign = 1;   /* sign of significand */
  i64 s = 0;      /* significand */
  int d = 0;      /* adjust exponent for shifting decimal point */
  int esign = 1;  /* sign of exponent */
  int e = 0;      /* exponent */

  double result;
  int nDigits = 0;



  if( enc==SQLITE_UTF16BE ) z++;

  /* skip leading spaces */
  while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
  if( z>=zEnd ){
    *pResult = 0.0;
    return 0;
  }

  /* get sign of significand */
  if( *z=='-' ){
    sign = -1;
    z+=incr;
  }else if( *z=='+' ){
    z+=incr;
................................................................................
    while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++;
  }
  if( z>=zEnd ) goto do_atof_calc;

  /* if exponent is present */
  if( *z=='e' || *z=='E' ){
    z+=incr;

    if( z>=zEnd ) goto do_atof_calc;
    /* get sign of exponent */
    if( *z=='-' ){
      esign = -1;
      z+=incr;
    }else if( *z=='+' ){
      z+=incr;
    }
    /* copy digits to exponent */
    while( z<zEnd && sqlite3Isdigit(*z) ){
      e = e*10 + (*z - '0');
      z+=incr;

    }
  }






do_atof_calc:
  /* adjust exponent by d, and update sign */
  e = (e*esign) + d;
  if( e<0 ) {
    esign = -1;
    e *= -1;
................................................................................
      result = (double)s;
    }
  }

  /* store the result */
  *pResult = result;

  /* return true if number and no extra chracters after */
  return z>=zEnd && sqlite3Isdigit(z[-incr]);
#else
  return !sqlite3Atoi64(z, pResult, length, enc);
#endif /* SQLITE_OMIT_FLOATING_POINT */
}

/*
** Compare the 19-character string zNum against the text representation







|





|
>
>
>
>
>
>
>
>
>
>
>
>






|
|
|
|
|
>


>
>





|
<
<
<







 







>












>


>
>
>
>
>







 







|
|







235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282



283
284
285
286
287
288
289
...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
...
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
  b = (unsigned char *)zRight;
  while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
  return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
}

/*
** The string z[] is an text representation of a real number.
** Convert this string to a double and write it into *pResult.
**
** The string z[] is length bytes in length (bytes, not characters) and
** uses the encoding enc.  The string is not necessarily zero-terminated.
**
** Return TRUE if the result is a valid real number (or integer) and FALSE
** if the string is empty or contains extraneous text.  Valid numbers
** are in one of these formats:
**
**    [+-]digits[E[+-]digits]
**    [+-]digits.[digits][E[+-]digits]
**    [+-].digits[E[+-]digits]
**
** Leading and trailing whitespace is ignored for the purpose of determining
** validity.
**
** If some prefix of the input string is a valid number, this routine
** returns FALSE but it still converts the prefix and writes the result
** into *pResult.
*/
int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
#ifndef SQLITE_OMIT_FLOATING_POINT
  int incr = (enc==SQLITE_UTF8?1:2);
  const char *zEnd = z + length;
  /* sign * significand * (10 ^ (esign * exponent)) */
  int sign = 1;    /* sign of significand */
  i64 s = 0;       /* significand */
  int d = 0;       /* adjust exponent for shifting decimal point */
  int esign = 1;   /* sign of exponent */
  int e = 0;       /* exponent */
  int eValid = 1;  /* True exponent is either not used or is well-formed */
  double result;
  int nDigits = 0;

  *pResult = 0.0;   /* Default return value, in case of an error */

  if( enc==SQLITE_UTF16BE ) z++;

  /* skip leading spaces */
  while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
  if( z>=zEnd ) return 0;




  /* get sign of significand */
  if( *z=='-' ){
    sign = -1;
    z+=incr;
  }else if( *z=='+' ){
    z+=incr;
................................................................................
    while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++;
  }
  if( z>=zEnd ) goto do_atof_calc;

  /* if exponent is present */
  if( *z=='e' || *z=='E' ){
    z+=incr;
    eValid = 0;
    if( z>=zEnd ) goto do_atof_calc;
    /* get sign of exponent */
    if( *z=='-' ){
      esign = -1;
      z+=incr;
    }else if( *z=='+' ){
      z+=incr;
    }
    /* copy digits to exponent */
    while( z<zEnd && sqlite3Isdigit(*z) ){
      e = e*10 + (*z - '0');
      z+=incr;
      eValid = 1;
    }
  }

  /* skip trailing spaces */
  if( nDigits && eValid ){
    while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
  }

do_atof_calc:
  /* adjust exponent by d, and update sign */
  e = (e*esign) + d;
  if( e<0 ) {
    esign = -1;
    e *= -1;
................................................................................
      result = (double)s;
    }
  }

  /* store the result */
  *pResult = result;

  /* return true if number and no extra non-whitespace chracters after */
  return z>=zEnd && nDigits>0 && eValid;
#else
  return !sqlite3Atoi64(z, pResult, length, enc);
#endif /* SQLITE_OMIT_FLOATING_POINT */
}

/*
** Compare the 19-character string zNum against the text representation

Changes to test/date.test.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  set sql [format {strftime('%%H:%%M:%%f',1237962480.%03d,'unixepoch')} $i]
  set res [format {06:28:00.%03d} $i]
  datetest 2.2c-$i $sql $res
}
datetest 2.3 {date('2003-10-22','weekday 0')} 2003-10-26
datetest 2.4 {date('2003-10-22','weekday 1')} 2003-10-27
datetest 2.4a {date('2003-10-22','weekday  1')} 2003-10-27
datetest 2.4b {date('2003-10-22','weekday  1x')} 2003-10-27
datetest 2.4c {date('2003-10-22','weekday  -1')} NULL
datetest 2.4d {date('2003-10-22','weakday  1x')} NULL
datetest 2.4e {date('2003-10-22','weekday ')} NULL
datetest 2.5 {date('2003-10-22','weekday 2')} 2003-10-28
datetest 2.6 {date('2003-10-22','weekday 3')} 2003-10-22
datetest 2.7 {date('2003-10-22','weekday 4')} 2003-10-23
datetest 2.8 {date('2003-10-22','weekday 5')} 2003-10-24







|







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  set sql [format {strftime('%%H:%%M:%%f',1237962480.%03d,'unixepoch')} $i]
  set res [format {06:28:00.%03d} $i]
  datetest 2.2c-$i $sql $res
}
datetest 2.3 {date('2003-10-22','weekday 0')} 2003-10-26
datetest 2.4 {date('2003-10-22','weekday 1')} 2003-10-27
datetest 2.4a {date('2003-10-22','weekday  1')} 2003-10-27
datetest 2.4b {date('2003-10-22','weekday  1x')} NULL
datetest 2.4c {date('2003-10-22','weekday  -1')} NULL
datetest 2.4d {date('2003-10-22','weakday  1x')} NULL
datetest 2.4e {date('2003-10-22','weekday ')} NULL
datetest 2.5 {date('2003-10-22','weekday 2')} 2003-10-28
datetest 2.6 {date('2003-10-22','weekday 3')} 2003-10-22
datetest 2.7 {date('2003-10-22','weekday 4')} 2003-10-23
datetest 2.8 {date('2003-10-22','weekday 5')} 2003-10-24

Changes to test/index.test.

528
529
530
531
532
533
534




535
536
537





538
539
540
541
542
543
544
545
    INSERT INTO t1 VALUES('12.32e+4',5);
    INSERT INTO t1 VALUES('12.36E+04',6);
    INSERT INTO t1 VALUES('12.36E+',7);
    INSERT INTO t1 VALUES('+123.10000E+0003',8);
    INSERT INTO t1 VALUES('+',9);
    INSERT INTO t1 VALUES('+12347.E+02',10);
    INSERT INTO t1 VALUES('+12347E+02',11);




    SELECT b FROM t1 ORDER BY a;
  }
} {8 5 2 1 3 6 11 9 10 4 7}





integrity_check index-15.1

# The following tests - index-16.* - test that when a table definition
# includes qualifications that specify the same constraint twice only a
# single index is generated to enforce the constraint.
#
# For example: "CREATE TABLE abc( x PRIMARY KEY, UNIQUE(x) );"
#







>
>
>
>
|

|
>
>
>
>
>
|







528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
    INSERT INTO t1 VALUES('12.32e+4',5);
    INSERT INTO t1 VALUES('12.36E+04',6);
    INSERT INTO t1 VALUES('12.36E+',7);
    INSERT INTO t1 VALUES('+123.10000E+0003',8);
    INSERT INTO t1 VALUES('+',9);
    INSERT INTO t1 VALUES('+12347.E+02',10);
    INSERT INTO t1 VALUES('+12347E+02',11);
    INSERT INTO t1 VALUES('+.125E+04',12);
    INSERT INTO t1 VALUES('-.125E+04',13);
    INSERT INTO t1 VALUES('.125E+0',14);
    INSERT INTO t1 VALUES('.125',15);
    SELECT b FROM t1 ORDER BY a, b;
  }
} {13 14 15 12 8 5 2 1 3 6 10 11 9 4 7}
do_test index-15.3 {
  execsql {
    SELECT b FROM t1 WHERE typeof(a) IN ('integer','real') ORDER BY b;
  }
} {1 2 3 5 6 8 10 11 12 13 14 15}
integrity_check index-15.4

# The following tests - index-16.* - test that when a table definition
# includes qualifications that specify the same constraint twice only a
# single index is generated to enforce the constraint.
#
# For example: "CREATE TABLE abc( x PRIMARY KEY, UNIQUE(x) );"
#

Added test/tkt-3998683a16.test.





























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 2010 September 30
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file implements regression tests for SQLite library. Specifically,
# it tests that ticket [3998683a16a7076e08f5585c1f4816414c8c653a] where in
# floating point values with a decimal point at the beginning or end
# of the mantissa are used.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test tkt-3998683a16.1 {
  db eval {
    CREATE TABLE t1(x, y REAL);
    INSERT INTO t1 VALUES(1, '1.0');
    INSERT INTO t1 VALUES(2, '.125');
    INSERT INTO t1 VALUES(3, '123.');
    INSERT INTO t1 VALUES(4, '123.e+2');
    INSERT INTO t1 VALUES(5, '.125e+3');
    INSERT INTO t1 VALUES(6, '123e4');
    INSERT INTO t1 VALUES(11, '  1.0');
    INSERT INTO t1 VALUES(12, '  .125');
    INSERT INTO t1 VALUES(13, '  123.');
    INSERT INTO t1 VALUES(14, '  123.e+2');
    INSERT INTO t1 VALUES(15, '  .125e+3');
    INSERT INTO t1 VALUES(16, '  123e4');
    INSERT INTO t1 VALUES(21, '1.0  ');
    INSERT INTO t1 VALUES(22, '.125  ');
    INSERT INTO t1 VALUES(23, '123.  ');
    INSERT INTO t1 VALUES(24, '123.e+2  ');
    INSERT INTO t1 VALUES(25, '.125e+3  ');
    INSERT INTO t1 VALUES(26, '123e4  ');
    SELECT x FROM t1 WHERE typeof(y)=='real' ORDER BY x;
  }
} {1 2 3 4 5 6 11 12 13 14 15 16 21 22 23 24 25 26}

finish_test