Skip to content

Latest commit

 

History

History
232 lines (141 loc) · 4.73 KB

File metadata and controls

232 lines (141 loc) · 4.73 KB

floor10f

Round a single-precision floating-point number to the nearest power of 10 toward negative infinity.

Usage

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

floor10f( x )

Rounds a single-precision floating-point number to the nearest power of 10 toward negative infinity.

var v = floor10f( -4.2 );
// returns -10.0

v = floor10f( -4.5 );
// returns -10.0

v = floor10f( -4.6 );
// returns -10.0

v = floor10f( 9.99999 );
// returns 1.0

v = floor10f( 9.5 );
// returns 1.0

v = floor10f( 13.0 );
// returns 10.0

v = floor10f( -13.0 );
// returns -100.0

v = floor10f( 0.0 );
// returns 0.0

v = floor10f( -0.0 );
// returns -0.0

v = floor10f( Infinity );
// returns Infinity

v = floor10f( -Infinity );
// returns -Infinity

v = floor10f( NaN );
// returns NaN

Notes

  • The function may not return accurate results for subnormals due to a general loss in precision.

    var v = floor10f( 1.0e-44 ); // should return 1.0e-44
    // returns 0.0

Examples

var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var floor10f = require( '@stdlib/math/base/special/floor10f' );

var opts = {
    'dtype': 'float32'
};
var x = uniform( 100, -50.0, 50.0, opts );

logEachMap( 'x: %f. Rounded: %f.', x, floor10f );

C APIs

Usage

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

stdlib_base_floor10f( x )

Rounds a single-precision floating-point number to the nearest power of 10 toward negative infinity.

float y = stdlib_base_floor10f( -4.2f );
// returns -10.0f

The function accepts the following arguments:

  • x: [in] float input value.
float stdlib_base_floor10f( const float x );

Examples

#include "stdlib/math/base/special/floor10f.h"
#include <stdio.h>

int main( void ) {
    const float x[] = { 3.14f, -3.14f, 0.0f, 1.0f / 0.0f };

    float y;
    int i;
    for ( i = 0; i < 4; i++ ) {
        y = stdlib_base_floor10f( x[ i ] );
        printf( "floor10f(%f) = %f\n", x[ i ], y );
    }
}

See Also