return 0;
}
-int
-main( void )
+static int
+test_truncd( void )
{
char buf[32];
- char *in, *out;
- int len;
- int i;
- int l;
- /* tr_truncd */
tr_snprintf( buf, sizeof( buf ), "%.2f%%", 99.999 );
check( !strcmp( buf, "100.00%" ) );
+
tr_snprintf( buf, sizeof( buf ), "%.2f%%", tr_truncd( 99.999, 2 ) );
check( !strcmp( buf, "99.99%" ) );
+ tr_snprintf( buf, sizeof( buf ), "%.4f", tr_truncd( 403650.656250, 4 ) );
+ check( !strcmp( buf, "403650.6562" ) );
+
+ return 0;
+}
+
+int
+main( void )
+{
+ char *in, *out;
+ int len;
+ int i;
+ int l;
+
/* base64 */
out = tr_base64_encode( "YOYO!", -1, &len );
check( out );
return i;
if( ( i = test_url( ) ) )
return i;
+ if( ( i = test_truncd( ) ) )
+ return i;
/* test that tr_cryptoRandInt() stays in-bounds */
for( i = 0; i < 100000; ++i )
tr_truncd( double x, int decimal_places )
{
const int i = (int) pow( 10, decimal_places );
- double x2 = (int)(x*i);
+ const double x2 = (int64_t)(x * i);
return x2 / i;
}