Round a single-precision floating-point number toward zero to
ndigits in baseb.
var truncbf = require( '@stdlib/math/base/special/truncbf' );Rounds a single-precision floating-point number toward zero to n digits in base b.
var v = truncbf( 3.14159, 2, 10 );
// returns 3.140000104904175
v = truncbf( 3.14159, 3, 10 );
// returns 3.1410000324249268
v = truncbf( 15.0, -1, 10 );
// returns 10.0
v = truncbf( -3.14159, 2, 10 );
// returns -3.140000104904175If provided NaN or a base of 0, the function returns NaN.
var v = truncbf( NaN, 2, 10 );
// returns NaN
v = truncbf( 3.14, 2, 0 );
// returns NaNIf provided x = ±0 or x = ±infinity, the function returns x.
var PINF = require( '@stdlib/constants/float32/pinf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var v = truncbf( 0.0, 2, 10 );
// returns 0.0
v = truncbf( -0.0, 2, 10 );
// returns -0.0
v = truncbf( PINF, 2, 10 );
// returns Infinity
v = truncbf( NINF, 2, 10 );
// returns -Infinity- This function is the single-precision floating-point equivalent of
truncb.
var randu = require( '@stdlib/random/base/randu' );
var truncbf = require( '@stdlib/math/base/special/truncbf' );
var x;
var i;
for ( i = 0; i < 100; i++ ) {
x = (randu() * 100.0) - 50.0;
console.log( 'truncbf(%d, 2, 10) = %d', x, truncbf( x, 2, 10 ) );
}#include "stdlib/math/base/special/truncbf.h"Rounds a single-precision floating-point number toward zero to n digits in base b.
float y = stdlib_base_truncbf( 3.14159f, 2, 10 );
// returns 3.14fThe function accepts the following arguments:
- x:
[in] floatinput value. - n:
[in] int32_tnumber of digits. - b:
[in] int32_tbase.
float stdlib_base_truncbf( const float x, const int32_t n, const int32_t b );#include "stdlib/math/base/special/truncbf.h"
#include <stdio.h>
int main( void ) {
const float x[] = { 3.14159f, -3.14159f, 15.0f, -15.0f };
const int32_t n[] = { 2, 3, -1, 0 };
const int32_t b = 10;
float y;
int i;
for ( i = 0; i < 4; i++ ) {
y = stdlib_base_truncbf( x[i], n[i], b );
printf( "truncbf(%f, %d, %d) = %f\n", x[i], n[i], b, y );
}
}