@stdlib/math-base-special-roundf
v0.1.1
Published
Round a single-precision floating-point number to the nearest integer.
Downloads
1,286
Readme
Round
Round a single-precision floating-point number to the nearest integer.
Installation
npm install @stdlib/math-base-special-roundfUsage
var roundf = require( '@stdlib/math-base-special-roundf' );roundf( x )
Rounds a single-precision floating-point number to the nearest integer.
var v = roundf( -4.2 );
// returns -4.0
v = roundf( -4.5 );
// returns -4.0
v = roundf( -4.6 );
// returns -5.0
v = roundf( 9.99999 );
// returns 10.0
v = roundf( 9.5 );
// returns 10.0
v = roundf( 9.2 );
// returns 9.0
v = roundf( 0.0 );
// returns 0.0
v = roundf( -0.0 );
// returns -0.0
v = roundf( Infinity );
// returns Infinity
v = roundf( -Infinity );
// returns -Infinity
v = roundf( NaN );
// returns NaNNotes
- Ties are rounded toward positive infinity.
Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var roundf = require( '@stdlib/math-base-special-roundf' );
var opts = {
'dtype': 'float32'
};
var x = uniform( 100, -50.0, 50.0, opts );
logEachMap( 'Value: %0.4f. Rounded: %0.4f.', x, roundf );C APIs
Usage
#include "stdlib/math/base/special/roundf.h"stdlib_base_roundf( x )
Rounds a single-precision floating-point number to the nearest integer.
float out = stdlib_base_roundf( -4.2f );
// returns -4.0fThe function accepts the following arguments:
- x:
[in] floatinput value.
float stdlib_base_roundf( const float x );Examples
#include "stdlib/math/base/special/roundf.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_roundf( x[ i ] );
printf( "roundf(%f) = %f\n", x[ i ], v );
}
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
