@stdlib/math-base-special-round-nearest-even
v0.1.1
Published
Round a double-precision floating-point number to the nearest integer value with ties rounding to the nearest even integer.
Readme
roundNearestEven
Round a double-precision floating-point number to the nearest integer value with ties rounding to the nearest even integer.
Installation
npm install @stdlib/math-base-special-round-nearest-evenUsage
var roundNearestEven = require( '@stdlib/math-base-special-round-nearest-even' );roundNearestEven( x )
Rounds a double-precision floating-point number to the nearest integer value with ties rounding to the nearest even integer.
var v = roundNearestEven( -3.5 );
// returns -4.0
v = roundNearestEven( -4.2 );
// returns -4.0
v = roundNearestEven( -4.5 );
// returns -4.0
v = roundNearestEven( -4.6 );
// returns -5.0
v = roundNearestEven( 9.99999 );
// returns 10.0
v = roundNearestEven( 8.5 );
// returns 8.0
v = roundNearestEven( 9.5 );
// returns 10.0
v = roundNearestEven( 9.2 );
// returns 9.0
v = roundNearestEven( 0.0 );
// returns 0.0
v = roundNearestEven( -0.0 );
// returns -0.0
v = roundNearestEven( Infinity );
// returns Infinity
v = roundNearestEven( -Infinity );
// returns -Infinity
v = roundNearestEven( NaN );
// returns NaNExamples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var roundNearestEven = require( '@stdlib/math-base-special-round-nearest-even' );
var opts = {
'dtype': 'float64'
};
var x = uniform( 100, -50.0, 50.0, opts );
logEachMap( 'roundNearestEven(%.4f) = %.4f', x, roundNearestEven );C APIs
Usage
#include "stdlib/math/base/special/round_nearest_even.h"stdlib_base_round_nearest_even( x )
Rounds a double-precision floating-point number to the nearest integer value with ties rounding to the nearest even integer.
double out = stdlib_base_round_nearest_even( -4.5 );
// returns -4.0The function accepts the following arguments:
- x:
[in] doubleinput value.
double stdlib_base_round_nearest_even( const double x );Examples
#include "stdlib/math/base/special/round_nearest_even.h"
#include <stdio.h>
int main( void ) {
const double x[] = { -5.0, -3.89, -2.78, -1.67, -0.50, 0.50, 1.67, 2.78, 3.89, 5.0 };
double v;
int i;
for ( i = 0; i < 10; i++ ) {
v = stdlib_base_round_nearest_even( x[ i ] );
printf( "roundNearestEven(%lf) = %lf\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.
