- Timestamp:
- Jul 24, 2010, 5:09:41 PM (12 years ago)
- Location:
- branches/2.0x/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0x/libtransmission/utils-test.c
r10965 r11050 354 354 } 355 355 356 static int 357 test_truncd( void ) 358 { 359 char buf[32]; 360 361 tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 ); 362 check( !strcmp( buf, "100.00%" ) ); 363 364 tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) ); 365 check( !strcmp( buf, "99.99%" ) ); 366 367 tr_snprintf( buf, sizeof( buf ), "%.4f", tr_truncd( 403650.656250, 4 ) ); 368 check( !strcmp( buf, "403650.6562" ) ); 369 370 return 0; 371 } 372 356 373 int 357 374 main( void ) 358 375 { 359 char buf[32];360 376 char *in, *out; 361 377 int len; 362 378 int i; 363 379 int l; 364 365 /* tr_truncd */366 tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 );367 check( !strcmp( buf, "100.00%" ) );368 tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) );369 check( !strcmp( buf, "99.99%" ) );370 380 371 381 /* base64 */ … … 402 412 if( ( i = test_url( ) ) ) 403 413 return i; 414 if( ( i = test_truncd( ) ) ) 415 return i; 404 416 405 417 /* test that tr_cryptoRandInt() stays in-bounds */ -
branches/2.0x/libtransmission/utils.c
r10964 r11050 1405 1405 { 1406 1406 const int i = (int) pow( 10, decimal_places ); 1407 double x2 = (int)(x*i);1407 const double x2 = (int64_t)(x * i); 1408 1408 return x2 / i; 1409 1409 }
Note: See TracChangeset
for help on using the changeset viewer.