SQLite

Check-in [7fca1bc4]
Login

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

Overview
Comment:Fix rounding in zero-precision %f and %g printf conversions. Forum post 393708f4a8. This bug was introduced by check-in [32befb224b254639] and first appeared in version 3.43.0.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7fca1bc482fc2456d75392eb42f768fda72631c9070de46b8123b1126e78306f
User & Date: drh 2024-02-17 03:32:31
Context
2024-02-19
12:20
Extend the strerror_r() result type discrepancy check in os_unix.c to include the Android NDK, as reported in forum post 3f13857fa4062301. The NDK's strerror_r() signature is version-dependent, whereas this change assumes int return (POSIX semantic) across all versions. (check-in: f18b2524 user: stephan tags: trunk)
2024-02-17
20:55
Add start of extension for incremental integrity-checks to ext/intck/. (check-in: 444e3c92 user: dan tags: incr-integrity-check)
03:36
Fix rounding in zero-precision %f and %g printf conversions. (check-in: 1ebea57f user: drh tags: branch-3.45)
03:32
Fix rounding in zero-precision %f and %g printf conversions. Forum post 393708f4a8. This bug was introduced by check-in [32befb224b254639] and first appeared in version 3.43.0. (check-in: 7fca1bc4 user: drh tags: trunk)
2024-02-16
21:30
Fix the subtype on the value column from json_each/json_tree for cases when the value is an array or object. Fix for the bug reported by forum post ecb94cd210. (check-in: 1c33c5db user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/printf.c.

494
495
496
497
498
499
500

501
502
503
504
505
506
507
        if( precision>SQLITE_FP_PRECISION_LIMIT ){
          precision = SQLITE_FP_PRECISION_LIMIT;
        }
#endif
        if( xtype==etFLOAT ){
          iRound = -precision;
        }else if( xtype==etGENERIC ){

          iRound = precision;
        }else{
          iRound = precision+1;
        }
        sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 26 : 16);
        if( s.isSpecial ){
          if( s.isSpecial==2 ){







>







494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
        if( precision>SQLITE_FP_PRECISION_LIMIT ){
          precision = SQLITE_FP_PRECISION_LIMIT;
        }
#endif
        if( xtype==etFLOAT ){
          iRound = -precision;
        }else if( xtype==etGENERIC ){
          if( precision==0 ) precision = 1;
          iRound = precision;
        }else{
          iRound = precision+1;
        }
        sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 26 : 16);
        if( s.isSpecial ){
          if( s.isSpecial==2 ){

Changes to src/util.c.

1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
  assert( v>0 );
  while( v ){  p->zBuf[i--] = (v%10) + '0'; v /= 10; }
  assert( i>=0 && i<sizeof(p->zBuf)-1 );
  p->n = sizeof(p->zBuf) - 1 - i;
  assert( p->n>0 );
  assert( p->n<sizeof(p->zBuf) );
  p->iDP = p->n + exp;
  if( iRound<0 ){
    iRound = p->iDP - iRound;
    if( iRound==0 && p->zBuf[i+1]>='5' ){
      iRound = 1;
      p->zBuf[i--] = '0';
      p->n++;
      p->iDP++;
    }







|







1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
  assert( v>0 );
  while( v ){  p->zBuf[i--] = (v%10) + '0'; v /= 10; }
  assert( i>=0 && i<sizeof(p->zBuf)-1 );
  p->n = sizeof(p->zBuf) - 1 - i;
  assert( p->n>0 );
  assert( p->n<sizeof(p->zBuf) );
  p->iDP = p->n + exp;
  if( iRound<=0 ){
    iRound = p->iDP - iRound;
    if( iRound==0 && p->zBuf[i+1]>='5' ){
      iRound = 1;
      p->zBuf[i--] = '0';
      p->n++;
      p->iDP++;
    }

Changes to test/printf.test.

3828
3829
3830
3831
3832
3833
3834

















3835
3836
#
db close
sqlite3 db test.db
sqlite3_db_config_lookaside db 0 0 0
do_execsql_test printf-18.1 {
  SELECT length( format('%,.249f', -5.0e-300) );
} {252}


















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
#
db close
sqlite3 db test.db
sqlite3_db_config_lookaside db 0 0 0
do_execsql_test printf-18.1 {
  SELECT length( format('%,.249f', -5.0e-300) );
} {252}

# 2024-02-16
# https://sqlite.org/forum/info/393708f4a8
#
# The problem introduced by on 2023-07-03 by
# https://sqlite.org/src/info/32befb224b254639
#
do_execsql_test printf-19.1 {
  SELECT format('%0.0f %0.0g %0.0g', 0.9, 0.09, 1.9);
} {{1 0.09 2}}
do_execsql_test printf-19.2 {
  SELECT format('%0.0f %#0.0f',0.0, 0.0);
} {{0 0.}}
do_execsql_test printf-19.3 {
  SELECT format('%,.0f %,.0f',12345e+10, 12345e+11);
} {{123,450,000,000,000 1,234,500,000,000,000}}


finish_test