/ Check-in [15202aee]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Improved rounding even on systems with an 8-byte "long double" type.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 15202aee150fa8e15fb90e90e5765c5e19a1eaf4896da2996a747636b76da8e6
User & Date: drh 2019-05-27 00:29:15
Context
2019-05-27
11:09
Fix a memory leak in the delta_parse() table-valued function of the fossildelta.c extension. check-in: c86ca3f0 user: drh tags: trunk
00:29
Improved rounding even on systems with an 8-byte "long double" type. check-in: 15202aee user: drh tags: trunk
2019-05-25
18:17
Performance enhancement in sqlite3AtoF(). About 8% faster. check-in: 81721aa5 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/printf.c.

523
524
525
526
527
528
529





530
531
532
533
534
535
536
537
        }
        if( xtype==etGENERIC && precision>0 ) precision--;
        testcase( precision>0xfff );
        idx = precision & 0xfff;
        rounder = arRound[idx%10];
        while( idx>=10 ){ rounder *= 1.0e-10; idx -= 10; }
        if( xtype==etFLOAT ){





          if( precision<17) rounder += realvalue*2.0e-16;
          realvalue += rounder;
        }
        /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
        exp = 0;
        if( sqlite3IsNaN((double)realvalue) ){
          bufpt = "NaN";
          length = 3;







>
>
>
>
>
|







523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
        }
        if( xtype==etGENERIC && precision>0 ) precision--;
        testcase( precision>0xfff );
        idx = precision & 0xfff;
        rounder = arRound[idx%10];
        while( idx>=10 ){ rounder *= 1.0e-10; idx -= 10; }
        if( xtype==etFLOAT ){
          double rx = (double)realvalue;
          sqlite3_uint64 u;
          int ex;
          memcpy(&u, &rx, sizeof(u));
          ex = -1023 + (int)((u>>52)&0x7ff);
          if( precision+(ex/3) < 15 ) rounder += realvalue*3e-16;
          realvalue += rounder;
        }
        /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
        exp = 0;
        if( sqlite3IsNaN((double)realvalue) ){
          bufpt = "NaN";
          length = 3;

Changes to test/round1.test.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Test cases for rounding behavior of floating point values.
#

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

if {$::longdouble_size<=8} {
  finish_test
  return
}

expr srand(0)
unset -nocomplain iTest
for {set iTest 1} {$iTest<=10000} {incr iTest} {
   set x1 [expr int(rand()*100000)]
   set x2 [expr int(rand()*100000)+1000*int(rand()*10000)]
   set n [expr int(rand()*8)+1]
   set x3 [string range [format %09d $x2] [expr {9-$n}] end]
   set r $x1.$x3
   set ans [string trimright $r 0]
   if {[string match *. $ans]} {set ans ${ans}0}







<
<
<
<
<


|







11
12
13
14
15
16
17





18
19
20
21
22
23
24
25
26
27
# Test cases for rounding behavior of floating point values.
#

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






expr srand(0)
unset -nocomplain iTest
for {set iTest 1} {$iTest<=50000} {incr iTest} {
   set x1 [expr int(rand()*100000)]
   set x2 [expr int(rand()*100000)+1000*int(rand()*10000)]
   set n [expr int(rand()*8)+1]
   set x3 [string range [format %09d $x2] [expr {9-$n}] end]
   set r $x1.$x3
   set ans [string trimright $r 0]
   if {[string match *. $ans]} {set ans ${ans}0}