SQLite

Check-in [a9759fc7]
Login

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

Overview
Comment:Avoid 32-bit roundoff error on the second argument to round(). Forum post 170aeab92a.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a9759fc78d6cb0df7c81f20c2c5c358729e571ebee50ee2b1441a15239d0b4b6
User & Date: drh 2024-12-18 18:29:19
References
2024-12-19
19:52
Correction to check-in [a9759fc78d6cb0df] - printf() parameters values must be integers. (check-in: 2db531d1 user: drh tags: trunk)
Context
2024-12-18
20:29
Fix possible integer oveflow in the second and third argument to substr(). (check-in: b04b4006 user: drh tags: trunk)
18:29
Avoid 32-bit roundoff error on the second argument to round(). Forum post 170aeab92a. (check-in: a9759fc7 user: drh tags: trunk)
03:41
Rename some var refs in ext/lsm1/Makefile for the new build process. (check-in: 0ce42fa5 user: stephan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/func.c.
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
}

/*
** Implementation of the round() function
*/
#ifndef SQLITE_OMIT_FLOATING_POINT
static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
  int n = 0;
  double r;
  char *zBuf;
  assert( argc==1 || argc==2 );
  if( argc==2 ){
    if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
    n = sqlite3_value_int(argv[1]);
    if( n>30 ) n = 30;
    if( n<0 ) n = 0;
  }
  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
  r = sqlite3_value_double(argv[0]);
  /* If Y==0 and X will fit in a 64-bit int,
  ** handle the rounding directly,







|





|







436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
}

/*
** Implementation of the round() function
*/
#ifndef SQLITE_OMIT_FLOATING_POINT
static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
  i64 n = 0;
  double r;
  char *zBuf;
  assert( argc==1 || argc==2 );
  if( argc==2 ){
    if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
    n = sqlite3_value_int64(argv[1]);
    if( n>30 ) n = 30;
    if( n<0 ) n = 0;
  }
  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
  r = sqlite3_value_double(argv[0]);
  /* If Y==0 and X will fit in a 64-bit int,
  ** handle the rounding directly,
Changes to test/func.test.
335
336
337
338
339
340
341



342
343
344
345
346
347
348
  } {9999999999999.6}
  do_test func-4.38 {
    execsql {SELECT round(9999999999999.556,2);}
  } {9999999999999.56}
  do_test func-4.39 {
    string tolower [db eval {SELECT round(1e500), round(-1e500);}]
  } {inf -inf}



}

# Test the upper() and lower() functions
#
do_test func-5.1 {
  execsql {SELECT upper(t1) FROM tbl1}
} {THIS PROGRAM IS FREE SOFTWARE}







>
>
>







335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
  } {9999999999999.6}
  do_test func-4.38 {
    execsql {SELECT round(9999999999999.556,2);}
  } {9999999999999.56}
  do_test func-4.39 {
    string tolower [db eval {SELECT round(1e500), round(-1e500);}]
  } {inf -inf}
  do_execsql_test func-4.40 {
    SELECT round(123.456 , 4294967297);
  } {123.456}
}

# Test the upper() and lower() functions
#
do_test func-5.1 {
  execsql {SELECT upper(t1) FROM tbl1}
} {THIS PROGRAM IS FREE SOFTWARE}