Skip to content

Commit 982db23

Browse files
committed
feat: add implementation of math/base/special/xlog1pyf
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: passed - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 65ac870 commit 982db23

File tree

29 files changed

+2191
-0
lines changed

29 files changed

+2191
-0
lines changed
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
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+
# xlog1pyf
22+
23+
> Compute `x * ln(y+1)` so that the result is `0` if `x = 0` for single-precision floating-point numbers.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var xlog1pyf = require( '@stdlib/math/base/special/xlog1pyf' );
31+
```
32+
33+
#### xlog1pyf( x, y )
34+
35+
Computes `x * ln(y+1)` so that the result is `0` if `x = 0` for single-precision floating-point numbers `x` and `y`.
36+
37+
```javascript
38+
var out = xlog1pyf( 3.0, 2.0 );
39+
// returns ~3.296
40+
41+
out = xlog1pyf( 1.5, 5.9 );
42+
// returns ~2.897
43+
44+
out = xlog1pyf( 0.9, 1.0 );
45+
// returns ~0.624
46+
47+
out = xlog1pyf( 1.0, 0.0 );
48+
// returns 0.0
49+
50+
out = xlog1pyf( 0.0, -2.0 );
51+
// returns 0.0
52+
53+
out = xlog1pyf( 1.5, NaN );
54+
// returns NaN
55+
56+
out = xlog1pyf( 0.0, NaN );
57+
// returns NaN
58+
59+
out = xlog1pyf( NaN, 2.3 );
60+
// returns NaN
61+
```
62+
63+
</section>
64+
65+
<!-- /.usage -->
66+
67+
<section class="examples">
68+
69+
## Examples
70+
71+
<!-- eslint no-undef: "error" -->
72+
73+
```javascript
74+
var randu = require( '@stdlib/random/base/randu' );
75+
var xlog1pyf = require( '@stdlib/math/base/special/xlog1pyf' );
76+
77+
var x;
78+
var y;
79+
var i;
80+
81+
for ( i = 0; i < 100; i++ ) {
82+
x = randu();
83+
if ( x < 0.5 ) {
84+
x = 0.0;
85+
}
86+
y = ( randu() * 20.0 ) - 5.0;
87+
console.log( 'xlog1pyf(%d, %d) = %d', x, y, xlog1pyf( x, y ) );
88+
}
89+
```
90+
91+
</section>
92+
93+
<!-- /.examples -->
94+
95+
<!-- C interface documentation. -->
96+
97+
* * *
98+
99+
<section class="c">
100+
101+
## C APIs
102+
103+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
104+
105+
<section class="intro">
106+
107+
</section>
108+
109+
<!-- /.intro -->
110+
111+
<!-- C usage documentation. -->
112+
113+
<section class="usage">
114+
115+
### Usage
116+
117+
```c
118+
#include "stdlib/math/base/special/xlog1pyf.h"
119+
```
120+
121+
#### stdlib_base_xlog1pyf( x, y )
122+
123+
Computes `x * ln(y+1)` so that the result is `0` if `x = 0` for single-precision floating-point numbers `x` and `y`.
124+
125+
```c
126+
float v = stdlib_base_xlog1pyf( 3.0f, 2.0f );
127+
// returns ~3.296f
128+
```
129+
130+
The function accepts the following arguments:
131+
132+
- **x**: `[in] float` input value.
133+
- **y**: `[in] float` input value.
134+
135+
```c
136+
float stdlib_base_xlog1pyf( const float x, const float y );
137+
```
138+
139+
</section>
140+
141+
<!-- /.usage -->
142+
143+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
144+
145+
<section class="notes">
146+
147+
</section>
148+
149+
<!-- /.notes -->
150+
151+
<!-- C API usage examples. -->
152+
153+
<section class="examples">
154+
155+
### Examples
156+
157+
```c
158+
#include "stdlib/math/base/special/xlog1pyf.h"
159+
#include <stdio.h>
160+
#include <stdlib.h>
161+
162+
int main( void ) {
163+
float out;
164+
float x;
165+
float y;
166+
int i;
167+
168+
for ( i = 0; i < 100; i++ ) {
169+
x = ( (float)rand() / (float)RAND_MAX ) * 100.0f;
170+
y = ( (float)rand() / (float)RAND_MAX ) * 5.0f;
171+
out = stdlib_base_xlog1pyf( x, y );
172+
printf( "xlog1pyf(%f, %f) = %f\n", x, y, out );
173+
}
174+
}
175+
```
176+
177+
</section>
178+
179+
<!-- /.examples -->
180+
181+
</section>
182+
183+
<!-- /.c -->
184+
185+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
186+
187+
<section class="related">
188+
189+
* * *
190+
191+
## See Also
192+
193+
- <span class="package-name">[`@stdlib/math/base/special/log1pf`][@stdlib/math/base/special/log1pf]</span><span class="delimiter">: </span><span class="description">evaluate the natural logarithm of 1+x for single-precision floating-point numbers.</span>
194+
- <span class="package-name">[`@stdlib/math/base/special/xlog1py`][@stdlib/math/base/special/xlog1py]</span><span class="delimiter">: </span><span class="description">compute `x * ln(y+1)` so that the result is `0` if `x = 0` for double-precision floating-point numbers.</span>
195+
- <span class="package-name">[`@stdlib/math/base/special/xlogy`][@stdlib/math/base/special/xlogy]</span><span class="delimiter">: </span><span class="description">compute `x * ln(y)` so that the result is `0` if `x = 0` for double-precision floating-point numbers.</span>
196+
197+
</section>
198+
199+
<!-- /.related -->
200+
201+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
202+
203+
<section class="links">
204+
205+
<!-- <related-links> -->
206+
207+
[@stdlib/math/base/special/log1pf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/log1pf
208+
209+
[@stdlib/math/base/special/xlog1py]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/xlog1py
210+
211+
[@stdlib/math/base/special/xlogy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/xlogy
212+
213+
<!-- </related-links> -->
214+
215+
</section>
216+
217+
<!-- /.links -->
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pkg = require( './../package.json' ).name;
27+
var xlog1pyf = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var out;
34+
var x;
35+
var y;
36+
var i;
37+
38+
x = uniform( 100, 0.0, 10.0 );
39+
y = uniform( 100, 0.0, 10.0 );
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
out = xlog1pyf( x[ i % x.length ], y[ i % y.length ] );
44+
if ( isnanf( out ) ) {
45+
b.fail( 'should not return NaN' );
46+
}
47+
}
48+
b.toc();
49+
if ( isnanf( out ) ) {
50+
b.fail( 'should not return NaN' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var format = require( '@stdlib/string/format' );
29+
var pkg = require( './../package.json' ).name;
30+
31+
32+
// VARIABLES //
33+
34+
var xlog1pyf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( xlog1pyf instanceof Error )
37+
};
38+
39+
40+
// MAIN //
41+
42+
bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
43+
var out;
44+
var x;
45+
var y;
46+
var i;
47+
48+
x = uniform( 100, 0.0, 100.0 );
49+
y = uniform( 100, 0.0, 5.0 );
50+
51+
b.tic();
52+
for ( i = 0; i < b.iterations; i++ ) {
53+
out = xlog1pyf( x[ i % x.length ], y[ i % y.length ] );
54+
if ( isnanf( out ) ) {
55+
b.fail( 'should not return NaN' );
56+
}
57+
}
58+
b.toc();
59+
if ( isnanf( out ) ) {
60+
b.fail( 'should not return NaN' );
61+
}
62+
b.pass( 'benchmark finished' );
63+
b.end();
64+
});

0 commit comments

Comments
 (0)