Round a numeric value to the nearest power of ten using single-precision floating-point arithmetic.
var round10f = require( '@stdlib/math/base/special/round10f' );Rounds a numeric value to the nearest power of ten using single-precision floating-point arithmetic.
var y;
y = round10f( 3.1415926 );
// returns 1.0
y = round10f( 123.456 );
// returns 100.0
y = round10f( -2.5 );
// returns -1.0
y = round10f( -0.0 );
// returns -0.0var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var round10f = require( '@stdlib/math/base/special/round10f' );
var opts = {
'dtype': 'float32'
};
var x = uniform( 100, -50.0, 50.0, opts );
logEachMap( 'x: %0.4f => %0.4f', x, round10f );This package provides a C API for rounding single-precision floating-point numbers to the nearest power of \(10\).
#include "stdlib/math/base/special/round10f.h"Rounds a single-precision floating-point number to the nearest power of ten.
float out = stdlib_base_round10f( 3.14f );
// returns 1.0f
out = stdlib_base_round10f( 123.456f );
// returns 100.0fArguments
- x:
[in] floatinput value.
Returns
float: rounded value.
float stdlib_base_round10f( const float x );#include "stdlib/math/base/special/round10f.h"
#include <stdio.h>
int main( void ) {
const float x[] = {
-5.0f, -3.89f, -2.78f, -1.67f, -0.56f,
0.56f, 1.67f, 2.78f, 3.89f, 5.0f
};
float v;
int i;
for ( i = 0; i < 10; i++ ) {
v = stdlib_base_round10f( x[ i ] );
printf( "round10f(%f) = %f\n", x[ i ], v );
}
}@stdlib/math/base/special/ceil10: round a numeric value to the nearest power of 10 toward positive infinity.@stdlib/math/base/special/floor10: round a numeric value to the nearest power of 10 toward negative infinity.@stdlib/math/base/special/round: round a numeric value to the nearest integer.@stdlib/math/base/special/round2: round a numeric value to the nearest power of two on a linear scale.