Skip to content

Commit 16c19b6

Browse files
authored
feat: add math/base/special/xlogyf
PR-URL: #2813 Ref: #649 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 71c43cf commit 16c19b6

29 files changed

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

0 commit comments

Comments
 (0)