Skip to content

feat: add math/base/special/round-nearest-even #7468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 69 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
cc37b2b
feat: add `math/base/special/round-nearest-even`
anandkaranubc Jun 24, 2025
8b10eb4
docs: update heading
kgryte Jun 26, 2025
669f20c
Merge branch 'stdlib-js:develop' into feat/round-nearest-even
anandkaranubc Jun 28, 2025
715ab2e
docs: update function description
anandkaranubc Jun 28, 2025
3eadb85
chore: add structured package data
anandkaranubc Jun 28, 2025
a747ea0
Merge branch 'stdlib-js:develop' into feat/round-nearest-even
anandkaranubc Jun 28, 2025
152c442
test: pass in opts to skip if addon is not available
Planeshifter Jun 28, 2025
574f245
fix: add missing include header
Planeshifter Jun 28, 2025
d0b13c8
test: pass in opts to skip if addon is not available
Planeshifter Jun 28, 2025
ceee2c3
chore: minor clean-up
Planeshifter Jun 28, 2025
54bf08e
chore: minor clean-up
Planeshifter Jun 28, 2025
ed9ac44
fix: add missing include header
Planeshifter Jun 28, 2025
c44169e
fix: correct variable name typo in hornerDescending function
Planeshifter Jun 28, 2025
d5fab27
chore: minor clean-up
Planeshifter Jun 28, 2025
600526c
fix: load correct float32 sqrt dependency
Planeshifter Jun 28, 2025
3dbdcb7
fix: use correct include header
Planeshifter Jun 28, 2025
e88de9a
revert: fix: correct variable name typo in hornerDescending function
kgryte Jun 28, 2025
96534a3
revert: fix: load correct float32 sqrt dependency
kgryte Jun 29, 2025
24195c0
chore: remove excess trailing newlines
stdlib-bot Jun 29, 2025
1038c68
feat: add `stats/base/ndarray/dcumin`
gururaj1512 Jun 29, 2025
a5b56f6
feat: add `stats/base/ndarray/scumin`
gururaj1512 Jun 29, 2025
1c60aef
feat: add C ndarray interface and refactor implementation for `stats/…
gururaj1512 Jun 29, 2025
6928166
feat: add C ndarray interface and refactor implementation for `stats/…
gururaj1512 Jun 29, 2025
d60a55a
feat: add C ndarray interface and refactor implementation for `stats/…
gururaj1512 Jun 29, 2025
2b21e93
chore: clean-up and update tests
kgryte Jun 29, 2025
a7be387
chore: add missing benchmark and examples dependencies
Planeshifter Jun 29, 2025
3de233d
chore: add missing eps dependency to benchmark and examples configs
Planeshifter Jun 29, 2025
cb89565
bench: add missing eps dependency so C benchmarks compile
Planeshifter Jun 29, 2025
dd59524
chore: add missing eps dependency to benchmark and examples configs
Planeshifter Jun 29, 2025
f267c86
bench: use correct Makefile for remaining Bradford distribution funct…
Planeshifter Jun 29, 2025
be7f1e3
chore: add missing eps dependency so C examples compile
Planeshifter Jun 29, 2025
fc0bc6f
docs: update REPL namespace documentation
stdlib-bot Jun 29, 2025
a1dd86a
feat: add support for `float16`, `complex32`, `int64`, and `uint64` d…
kgryte Jun 29, 2025
5855b59
feat: add support for `float16`, `complex32`, `int64`, and `uint64` d…
kgryte Jun 29, 2025
4d58080
feat: add support for `float16`, `complex32`, `int64`, and `uint64` d…
kgryte Jun 29, 2025
2fd968b
feat: add support for `float16`, `complex32`, `int64`, and `uint64` d…
kgryte Jun 29, 2025
c58f497
fix: add missing table
kgryte Jun 29, 2025
e259ee8
bench: ensure values are within bounds
kgryte Jun 29, 2025
5200f84
fix: update type definition to include `const` qualifiers
kgryte Jun 29, 2025
df812ab
feat: add missing tests to `ndarray/base/includes`
headlessNode Jun 29, 2025
9eae3de
feat: add `stats/strided/smeanors`
gururaj1512 Jun 29, 2025
88ed279
remove: remove `smeanors` from namespace
gururaj1512 Jun 29, 2025
947c1db
refactor: update paths
gururaj1512 Jun 29, 2025
9563e67
remove: remove `stats/base/smeanors`
gururaj1512 Jun 29, 2025
75bd93c
feat: add `stats/strided/smeanlipw`
gururaj1512 Jun 29, 2025
d3acc25
remove: remove `smeanlipw` from namespace
gururaj1512 Jun 29, 2025
d8f98a9
refactor: update paths
gururaj1512 Jun 29, 2025
6dc1aa4
remove: remove `stats/base/smeanlipw`
gururaj1512 Jun 29, 2025
03f032d
feat: add `stats/strided/smeankbn2`
gururaj1512 Jun 29, 2025
e78f90d
remove: remove `smeankbn2` from namespace
gururaj1512 Jun 29, 2025
227b04e
refactor: update paths
gururaj1512 Jun 29, 2025
70e228b
remove: remove `stats/base/smeankbn2`
gururaj1512 Jun 29, 2025
cf134de
feat: add `stats/strided/smeankbn`
gururaj1512 Jun 29, 2025
a8f2745
remove: remove `smeankbn` from namespace
gururaj1512 Jun 29, 2025
d0e1121
refactor: update paths
gururaj1512 Jun 29, 2025
7cf05f6
remove: remove `stats/base/smeankbn`
gururaj1512 Jun 29, 2025
bdd7fb3
chore: fix EditorConfig lint errors
deepak427 Jun 29, 2025
efcca56
docs: fix include header path in examples
Planeshifter Jun 29, 2025
fdd3f19
docs: clean-up examples
Planeshifter Jun 29, 2025
e4e97ae
docs: minor clean-up
Planeshifter Jun 29, 2025
c6c7c3c
chore: minor clean-up
Planeshifter Jun 29, 2025
999f8d7
docs: update description to match main.js and add missing quote
Planeshifter Jun 29, 2025
ffbb630
chore: update notes and ensure n is first argument in examples
Planeshifter Jun 29, 2025
4f95fa5
docs: minor clean-up
Planeshifter Jun 29, 2025
fba3c64
docs: resolve NaN return values in `maxabsn` and `minabsn` examples
Planeshifter Jun 29, 2025
1402615
fix: update supported dtypes
kgryte Jun 29, 2025
f92db69
build: fix function aliases
kgryte Jun 29, 2025
8f5c0d6
chore: update metadata
anandkaranubc Jun 29, 2025
7843f12
Merge branch 'stdlib-js:develop' into feat/round-nearest-even
anandkaranubc Jun 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
<!--

@license Apache-2.0

Copyright (c) 2025 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# roundNearestEven

> Round a double-precision floating-point number to the nearest integer value with ties rounding to the nearest even integer.

<section class="usage">

## Usage

```javascript
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.

```javascript
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 NaN
```

</section>

<!-- /.usage -->

<section class="notes">

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
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 );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#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.

```c
double out = stdlib_base_round_nearest_even( -4.5 );
// returns -4.0
```

The function accepts the following arguments:

- **x**: `[in] double` input value.

```c
double stdlib_base_round_nearest_even( const double x );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

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

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var roundNearestEven = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var x;
var y;
var i;

x = uniform( 100, -500.0, 500.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = roundNearestEven( x[ i%x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var roundNearestEven = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( roundNearestEven instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var x;
var y;
var i;

x = uniform( 100, -500.0, 500.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = roundNearestEven( x[ i%x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading