Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | A second approach to working on the round() function so that it gives a small boost to numbers that are ...49999999 such that they round up. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | round-up-2 |
Files: | files | file ages | folders |
SHA3-256: |
44dd632896e688a7d73707f43261577b |
User & Date: | drh 2024-06-11 22:47:33 |
Context
2024-06-12
| ||
00:30 | Test cases for the round() function for values within one epsilon of the 5 round-up threshold. (check-in: 552b1b10 user: drh tags: round-up-2) | |
2024-06-11
| ||
22:47 | A second approach to working on the round() function so that it gives a small boost to numbers that are ...49999999 such that they round up. (check-in: 44dd6328 user: drh tags: round-up-2) | |
17:04 | Remove some dead JS code and update some JS docs. (check-in: 6935ac71 user: stephan tags: trunk) | |
Changes
Changes to src/func.c.
︙ | ︙ | |||
431 432 433 434 435 436 437 438 439 440 441 442 | p2 = len-p1; if( p2<0 ) p2 = 0; } sqlite3_result_blob64(context, (char*)&z[p1], (u64)p2, SQLITE_TRANSIENT); } } /* ** Implementation of the round() function */ #ifndef SQLITE_OMIT_FLOATING_POINT static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ | > > > > > > > > > > > > > > > > > > > > > > | | | > > > > > > > > < < < < < < | > | | < < < | < | < | 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | p2 = len-p1; if( p2<0 ) p2 = 0; } sqlite3_result_blob64(context, (char*)&z[p1], (u64)p2, SQLITE_TRANSIENT); } } /* ** The library round() function is only available if ** SQLITE_ENABLE_MATH_FUNCTIONS is defined. Without that macro, we ** have to grow our own. ** ** The sqlite3Round(x) routine only needs to deal with non-negative ** numbers. */ #ifdef SQLITE_ENABLE_MATH_FUNCTIONS # define sqlite3Round(X) round(X) #else static double sqlite3Round(double x){ assert( x>=0.0 ); if( x>+4503599627370496.0 ){ return x; }else{ sqlite3_int64 ii = (sqlite3_int64)(x+0.5); return (double)ii; } } #endif /* ** Implementation of the round() function */ #ifndef SQLITE_OMIT_FLOATING_POINT static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; /* Second argument. Digits to the right of decimal point */ double r; /* First argument. Value to be rounded */ double rX = 1.0; /* Scaling factor. pow(10,n) */ double rSgn; /* Sign of the first first */ static const double rTwoPowerMinus52 = /* pow(2,-52) */ 2.220446049250313080847263336181640625e-16; assert( argc==1 || argc==2 ); if( argc==2 ){ double rY = 10; int i; 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; for(i=n, rY=10; i>0; i>>=1, rY=rY*rY){ if( i&1 ) rX *= rY; } } if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; r = sqlite3_value_double(argv[0]); if( r<0 ){ rSgn = -1.0; r = -r; }else{ rSgn = 1.0; } r = rSgn*sqlite3Round(r*rX + rX*r*rTwoPowerMinus52)/rX; sqlite3_result_double(context, r); } #endif /* ** Allocate nByte bytes of space using sqlite3Malloc(). If the ** allocation fails, call sqlite3_result_error_nomem() to notify |
︙ | ︙ | |||
2501 2502 2503 2504 2505 2506 2507 | int argc, sqlite3_value **argv ){ assert( argc==0 ); (void)argv; sqlite3_result_double(context, M_PI); } | < | 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 | int argc, sqlite3_value **argv ){ assert( argc==0 ); (void)argv; sqlite3_result_double(context, M_PI); } #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */ /* ** Implementation of sign(X) function. */ static void signFunc( sqlite3_context *context, |
︙ | ︙ |