Skip to content

Latest commit

 

History

History
185 lines (116 loc) · 4.33 KB

File metadata and controls

185 lines (116 loc) · 4.33 KB

round10f

Round a numeric value to the nearest power of ten using single-precision floating-point arithmetic.

Usage

var round10f = require( '@stdlib/math/base/special/round10f' );

round10f( x )

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.0

Examples

var 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 );

C APIs

This package provides a C API for rounding single-precision floating-point numbers to the nearest power of \(10\).

Usage

#include "stdlib/math/base/special/round10f.h"

stdlib_base_round10f( x )

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.0f

Arguments

  • x: [in] float input value.

Returns

  • float: rounded value.
float stdlib_base_round10f( const float x );

Examples

#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 );
    }
}

See Also