Skip to content

Commit 8f70282

Browse files
committed
Auto-generated commit
1 parent ad889e1 commit 8f70282

File tree

25 files changed

+2583
-0
lines changed

25 files changed

+2583
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`a068c72`](https://github.com/stdlib-js/stdlib/commit/a068c72880b9f3757d8b00ec945eb4e9cba31a8b) - add `math/base/special/roundnf` [(#9389)](https://github.com/stdlib-js/stdlib/pull/9389)
1314
- [`cb09f58`](https://github.com/stdlib-js/stdlib/commit/cb09f5862f03c3056c8259164653940108068f30) - add `math/base/special/fast/atanhf` [(#9046)](https://github.com/stdlib-js/stdlib/pull/9046)
1415
- [`542d57c`](https://github.com/stdlib-js/stdlib/commit/542d57c97e7b8e8d9b41221d86c5378fa02d0d87) - add `math/base/special/floornf` [(#4881)](https://github.com/stdlib-js/stdlib/pull/4881)
1516
- [`ea8228b`](https://github.com/stdlib-js/stdlib/commit/ea8228b082c03c6c8c8182d237c709ae279c05d2) - add `math/base/special/acoshf` [(#5812)](https://github.com/stdlib-js/stdlib/pull/5812)
@@ -714,6 +715,7 @@ A total of 80 issues were closed in this release:
714715

715716
<details>
716717

718+
- [`a068c72`](https://github.com/stdlib-js/stdlib/commit/a068c72880b9f3757d8b00ec945eb4e9cba31a8b) - **feat:** add `math/base/special/roundnf` [(#9389)](https://github.com/stdlib-js/stdlib/pull/9389) _(by Aman Singh, Karan Anand, Philipp Burckhardt, stdlib-bot)_
717719
- [`518339b`](https://github.com/stdlib-js/stdlib/commit/518339b9e202765284968c5bb40a458bf25c9425) - **chore:** remove extra empty line [(#9617)](https://github.com/stdlib-js/stdlib/pull/9617) _(by stdlib-bot)_
718720
- [`8e05341`](https://github.com/stdlib-js/stdlib/commit/8e0534149457bd04a06ae3c59d726191e32a1dcf) - **chore:** clean-up _(by Athan Reines)_
719721
- [`cb09f58`](https://github.com/stdlib-js/stdlib/commit/cb09f5862f03c3056c8259164653940108068f30) - **feat:** add `math/base/special/fast/atanhf` [(#9046)](https://github.com/stdlib-js/stdlib/pull/9046) _(by Nakul Krishnakumar, Philipp Burckhardt, stdlib-bot)_

base/special/roundnf/README.md

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# roundnf
22+
23+
> Round a single-precision floating-point number to the nearest multiple of 10^n.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var roundnf = require( '@stdlib/math/base/special/roundnf' );
31+
```
32+
33+
#### roundnf( x, n )
34+
35+
Rounds a single-precision floating-point number to the nearest multiple of `10^n`.
36+
37+
```javascript
38+
// Round a value to 2 decimal places:
39+
var v = roundnf( 3.1415927410125732, -2 );
40+
// returns ~3.14
41+
42+
// If n = 0, `roundnf` behaves like `roundf`:
43+
v = roundnf( 3.1415927410125732, 0 );
44+
// returns 3.0
45+
46+
// Round a value to the nearest thousand:
47+
v = roundnf( 12368.0, 3 );
48+
// returns ~12000.0
49+
```
50+
51+
</section>
52+
53+
<!-- /.usage -->
54+
55+
<section class="notes">
56+
57+
## Notes
58+
59+
- When operating on [floating-point numbers][ieee754] in bases other than `2`, rounding to specified digits can be **inexact**. For example,
60+
61+
```javascript
62+
var x = 0.2 + 0.1;
63+
// returns 0.30000000000000004
64+
65+
// Should round to 0.3...
66+
var v = roundnf( x, -16 );
67+
// returns 0.30000001192092896
68+
```
69+
70+
- Ties are rounded toward positive infinity.
71+
72+
</section>
73+
74+
<!-- /.notes -->
75+
76+
<section class="examples">
77+
78+
## Examples
79+
80+
<!-- eslint no-undef: "error" -->
81+
82+
```javascript
83+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
84+
var uniform = require( '@stdlib/random/array/uniform' );
85+
var logEachMap = require( '@stdlib/console/log-each-map' );
86+
var roundnf = require( '@stdlib/math/base/special/roundnf' );
87+
88+
var x = uniform( 100, -50.0, 50.0, {
89+
'dtype': 'float32'
90+
});
91+
92+
var n = discreteUniform( 100, -5, 0, {
93+
'dtype': 'int32'
94+
});
95+
96+
logEachMap( 'x: %0.8f. Number of decimals: %d. Rounded: %0.8f', x, n, roundnf );
97+
```
98+
99+
</section>
100+
101+
<!-- /.examples -->
102+
103+
<!-- C interface documentation. -->
104+
105+
* * *
106+
107+
<section class="c">
108+
109+
## C APIs
110+
111+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
112+
113+
<section class="intro">
114+
115+
</section>
116+
117+
<!-- /.intro -->
118+
119+
<!-- C usage documentation. -->
120+
121+
<section class="usage">
122+
123+
### Usage
124+
125+
```c
126+
#include "stdlib/math/base/special/roundnf.h"
127+
```
128+
129+
#### stdlib_base_roundnf( x, n )
130+
131+
Rounds a single-precision floating-point number to the nearest multiple of `10^n`.
132+
133+
```c
134+
// Round a value to 2 decimal places:
135+
float y = stdlib_base_roundnf( 3.14159f, -2 );
136+
// returns ~3.14f
137+
138+
// If n = 0, `roundnf` behaves like `roundf`:
139+
y = stdlib_base_roundnf( 3.14159f, 0 );
140+
// returns 3.0f
141+
```
142+
143+
The function accepts the following arguments:
144+
145+
- **x**: `[in] float` input value.
146+
- **n**: `[in] int32_t` integer power of 10.
147+
148+
```c
149+
float stdlib_base_roundnf( const float x, const int32_t n );
150+
```
151+
152+
</section>
153+
154+
<!-- /.usage -->
155+
156+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
157+
158+
<section class="notes">
159+
160+
</section>
161+
162+
<!-- /.notes -->
163+
164+
<!-- C API usage examples. -->
165+
166+
<section class="examples">
167+
168+
### Examples
169+
170+
```c
171+
#include "stdlib/math/base/special/roundnf.h"
172+
#include <stdio.h>
173+
174+
int main( void ) {
175+
const float x[] = { 3.14f, -3.14f, 0.0f, 0.0f/0.0f };
176+
177+
float y;
178+
int i;
179+
for ( i = 0; i < 4; i++ ) {
180+
y = stdlib_base_roundnf( x[ i ], -2 );
181+
printf( "roundnf(%f, -2) = %f\n", x[ i ], y );
182+
}
183+
}
184+
```
185+
186+
</section>
187+
188+
<!-- /.examples -->
189+
190+
</section>
191+
192+
<!-- /.c -->
193+
194+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
195+
196+
<section class="related">
197+
198+
</section>
199+
200+
<!-- /.related -->
201+
202+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
203+
204+
<section class="links">
205+
206+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
207+
208+
<!-- <related-links> -->
209+
210+
<!-- </related-links> -->
211+
212+
</section>
213+
214+
<!-- /.links -->
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
26+
var isnanf = require( './../../../../base/assert/is-nanf' );
27+
var pkg = require( './../package.json' ).name;
28+
var roundnf = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var x;
35+
var n;
36+
var y;
37+
var i;
38+
39+
x = uniform( 100, -100.0, 100.0, {
40+
'dtype': 'float32'
41+
});
42+
n = discreteUniform( 100, -5, 0 );
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
y = roundnf( x[ i%x.length ], n[ i%n.length ] );
47+
if ( isnanf( y ) ) {
48+
b.fail( 'should not return NaN' );
49+
}
50+
}
51+
b.toc();
52+
if ( isnanf( y ) ) {
53+
b.fail( 'should not return NaN' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var randu = require( '@stdlib/random/base/randu' );
26+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
27+
var isnanf = require( './../../../../base/assert/is-nanf' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var pkg = require( './../package.json' ).name;
30+
31+
32+
// VARIABLES //
33+
34+
var roundnf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( roundnf instanceof Error )
37+
};
38+
39+
40+
// MAIN //
41+
42+
bench( pkg+'::native', opts, function benchmark( b ) {
43+
var x;
44+
var n;
45+
var y;
46+
var i;
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
x = ( randu() * 100.0 ) - 50.0;
51+
n = discreteUniform( -5, 0 );
52+
y = roundnf( x, n );
53+
if ( isnanf( y ) ) {
54+
b.fail( 'should not return NaN' );
55+
}
56+
}
57+
b.toc();
58+
if ( isnanf( y ) ) {
59+
b.fail( 'should not return NaN' );
60+
}
61+
b.pass( 'benchmark finished' );
62+
b.end();
63+
});

0 commit comments

Comments
 (0)