Skip to content

Commit a960eb4

Browse files
authored
Merge branch 'stdlib-js:develop' into svar
2 parents b663020 + 5cddadf commit a960eb4

File tree

107 files changed

+9331
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+9331
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
type: amend-message
3+
---
4+
feat: add Wald distribution PDF
5+
6+
PR-URL: #9324
7+
Ref: #209
8+
9+
Reviewed-by: Philipp Burckhardt <[email protected]>

lib/node_modules/@stdlib/math/base/special/fast/atanhf/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ int main( void ) {
196196
197197
<section class="related">
198198
199-
200199
</section>
201200
202201
<!-- /.related -->
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, -7 );
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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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( '@stdlib/math/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+
'dtype': 'int32'
44+
});
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
y = roundnf( x[ i%x.length ], n[ i%n.length ] );
49+
if ( isnanf( y ) ) {
50+
b.fail( 'should not return NaN' );
51+
}
52+
}
53+
b.toc();
54+
if ( isnanf( y ) ) {
55+
b.fail( 'should not return NaN' );
56+
}
57+
b.pass( 'benchmark finished' );
58+
b.end();
59+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 uniform = require( '@stdlib/random/array/uniform' );
26+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
27+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var format = require( '@stdlib/string/format' );
30+
var pkg = require( './../package.json' ).name;
31+
32+
33+
// VARIABLES //
34+
35+
var roundnf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
36+
var opts = {
37+
'skip': ( roundnf instanceof Error )
38+
};
39+
40+
41+
// MAIN //
42+
43+
bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
44+
var x;
45+
var n;
46+
var y;
47+
var i;
48+
49+
x = uniform( 100, -100.0, 100.0, {
50+
'dtype': 'float32'
51+
});
52+
n = discreteUniform( 100, -5, 0, {
53+
'dtype': 'int32'
54+
});
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
y = roundnf( x[ i%x.length ], n[ i%n.length ] );
59+
if ( isnanf( y ) ) {
60+
b.fail( 'should not return NaN' );
61+
}
62+
}
63+
b.toc();
64+
if ( isnanf( y ) ) {
65+
b.fail( 'should not return NaN' );
66+
}
67+
b.pass( 'benchmark finished' );
68+
b.end();
69+
});

0 commit comments

Comments
 (0)