/ Check-in [fd7bd4a5]
Login

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

Overview
Comment:Round-trip conversions of real->text->real are now lossless on x64 with GCC. Untested on other platforms so far. Still a corner-case problem with round().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | floating-point-conversions
Files: files | file ages | folders
SHA1:fd7bd4a59361be41b10522abc212cf56fb5e35b4
User & Date: drh 2012-06-19 03:35:05
Context
2012-06-19
03:59
Fix an incorrect testcase for the round() function. All tests are passing now, including new real->text->real round-trip tests. check-in: 963eb24f user: drh tags: floating-point-conversions
03:35
Round-trip conversions of real->text->real are now lossless on x64 with GCC. Untested on other platforms so far. Still a corner-case problem with round(). check-in: fd7bd4a5 user: drh tags: floating-point-conversions
03:11
Improved accuracy on text-to-real and real-to-text conversions. Most conversions now round-trip correctly. Still need to fix some corner cases. check-in: 8ecffca9 user: drh tags: floating-point-conversions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/printf.c.

426
427
428
429
430
431
432

433
434
435
436
437
438
439
        if( sqlite3IsNaN((double)realvalue) ){
          bufpt = "NaN";
          length = 3;
          break;
        }
        if( realvalue>0.0 ){
          LONGDOUBLE_TYPE scale = 1.0;

          while( realvalue>=1e64*scale && exp<=350 ){ scale *= 1e64; exp+=64; }
          while( realvalue>=1e8*scale && exp<=350 ){ scale *= 1e8; exp+=8; }
          while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; }
          realvalue /= scale;
          while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
          while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
          if( exp>350 ){







>







426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
        if( sqlite3IsNaN((double)realvalue) ){
          bufpt = "NaN";
          length = 3;
          break;
        }
        if( realvalue>0.0 ){
          LONGDOUBLE_TYPE scale = 1.0;
          while( realvalue>=1e100*scale && exp<=350 ){ scale *= 1e100;exp+=100;}
          while( realvalue>=1e64*scale && exp<=350 ){ scale *= 1e64; exp+=64; }
          while( realvalue>=1e8*scale && exp<=350 ){ scale *= 1e8; exp+=8; }
          while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; }
          realvalue /= scale;
          while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
          while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
          if( exp>350 ){

Changes to test/atof1.test.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Tests of the sqlite3AtoF() function.
#

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

expr srand(1)
for {set i 1} {$i<10000} {incr i} {
  set pow [expr {int((rand()-0.5)*100)}]
  set x [expr {pow((rand()-0.5)*2*rand(),$pow)}]
  set xf [format %.32e $x]

  # Verify that text->real conversions get exactly same ieee754 floating-
  # point value in SQLite as they do in TCL.
  #
................................................................................
      db eval "SELECT $xf+0.0 AS a, \$x AS b" {
        puts [format "\n%.60e\n%.60e\n%.60e" $x $a $b]
      }
    }
    set y
  } {1}

  # FIX ME.  The following tests (real->text->real round-trips) sometimes
  # fail for large floating-point values.  Skip them for now...
  #
  if {abs($x)>1e50} continue

  # Verify that round-trip real->text->real conversions using the quote()
  # function preserve the bits of the numeric value exactly.
  #
  do_test 1.$i.2 {
    set y [db eval {SELECT $x=CAST(quote($x) AS real)}]
    if {!$y} {
      db eval {SELECT real2hex($x) a, real2hex(CAST(quote($x) AS real)) b} {}







|







 







<
<
<
<
<







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
31
32
33
34
35
36
37





38
39
40
41
42
43
44
# Tests of the sqlite3AtoF() function.
#

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

expr srand(1)
for {set i 1} {$i<20000} {incr i} {
  set pow [expr {int((rand()-0.5)*100)}]
  set x [expr {pow((rand()-0.5)*2*rand(),$pow)}]
  set xf [format %.32e $x]

  # Verify that text->real conversions get exactly same ieee754 floating-
  # point value in SQLite as they do in TCL.
  #
................................................................................
      db eval "SELECT $xf+0.0 AS a, \$x AS b" {
        puts [format "\n%.60e\n%.60e\n%.60e" $x $a $b]
      }
    }
    set y
  } {1}






  # Verify that round-trip real->text->real conversions using the quote()
  # function preserve the bits of the numeric value exactly.
  #
  do_test 1.$i.2 {
    set y [db eval {SELECT $x=CAST(quote($x) AS real)}]
    if {!$y} {
      db eval {SELECT real2hex($x) a, real2hex(CAST(quote($x) AS real)) b} {}