@stdlib/math-base-special-nanmax 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +130 -6
- package/include/stdlib/math/base/special/nanmax.h +38 -0
- package/lib/native.js +55 -0
- package/manifest.json +75 -0
- package/package.json +7 -2
- package/src/addon.c +22 -0
- package/src/main.c +43 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -102,6 +102,130 @@ var v = nanmax( NaN, NaN );
|
|
|
102
102
|
|
|
103
103
|
</section>
|
|
104
104
|
|
|
105
|
+
<!-- /.notes -->
|
|
106
|
+
|
|
107
|
+
<!-- Package usage examples. -->
|
|
108
|
+
|
|
109
|
+
<section class="examples">
|
|
110
|
+
|
|
111
|
+
## Examples
|
|
112
|
+
|
|
113
|
+
<!-- eslint no-undef: "error" -->
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
var nanmax = require( '@stdlib/math-base-special-nanmax' );
|
|
117
|
+
|
|
118
|
+
var m = nanmax( 3.0, 4.0 );
|
|
119
|
+
console.log( m );
|
|
120
|
+
// => 4.0
|
|
121
|
+
|
|
122
|
+
m = nanmax( NaN, 4.0 );
|
|
123
|
+
console.log( m );
|
|
124
|
+
// => 4.0
|
|
125
|
+
|
|
126
|
+
m = nanmax( 4.0, NaN );
|
|
127
|
+
console.log( m );
|
|
128
|
+
// => 4.0
|
|
129
|
+
|
|
130
|
+
m = nanmax( NaN, NaN );
|
|
131
|
+
console.log( m );
|
|
132
|
+
// => NaN
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
</section>
|
|
136
|
+
|
|
137
|
+
<!-- /.examples -->
|
|
138
|
+
|
|
139
|
+
<!-- C interface documentation. -->
|
|
140
|
+
|
|
141
|
+
* * *
|
|
142
|
+
|
|
143
|
+
<section class="c">
|
|
144
|
+
|
|
145
|
+
## C APIs
|
|
146
|
+
|
|
147
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
148
|
+
|
|
149
|
+
<section class="intro">
|
|
150
|
+
|
|
151
|
+
</section>
|
|
152
|
+
|
|
153
|
+
<!-- /.intro -->
|
|
154
|
+
|
|
155
|
+
<!-- C usage documentation. -->
|
|
156
|
+
|
|
157
|
+
<section class="usage">
|
|
158
|
+
|
|
159
|
+
### Usage
|
|
160
|
+
|
|
161
|
+
```c
|
|
162
|
+
#include "stdlib/math/base/special/nanmax.h"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### stdlib_base_nanmax( x, y )
|
|
166
|
+
|
|
167
|
+
Returns the maximum value, ignoring NaN.
|
|
168
|
+
|
|
169
|
+
```c
|
|
170
|
+
double out = stdlib_base_nanmax( 4.2, 3.14 );
|
|
171
|
+
// returns 4.2
|
|
172
|
+
|
|
173
|
+
out = stdlib_base_nanmax( 4.14, 0.0 / 0.0 );
|
|
174
|
+
// returns 4.14
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The function accepts the following arguments:
|
|
178
|
+
|
|
179
|
+
- **x**: `[in] double` input value.
|
|
180
|
+
- **y**: `[in] double` input value.
|
|
181
|
+
|
|
182
|
+
```c
|
|
183
|
+
double stdlib_base_nanmax( const double x, const double y );
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
</section>
|
|
187
|
+
|
|
188
|
+
<!-- /.usage -->
|
|
189
|
+
|
|
190
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
191
|
+
|
|
192
|
+
<section class="notes">
|
|
193
|
+
|
|
194
|
+
</section>
|
|
195
|
+
|
|
196
|
+
<!-- /.notes -->
|
|
197
|
+
|
|
198
|
+
<!-- C API usage examples. -->
|
|
199
|
+
|
|
200
|
+
<section class="examples">
|
|
201
|
+
|
|
202
|
+
### Examples
|
|
203
|
+
|
|
204
|
+
```c
|
|
205
|
+
#include "stdlib/math/base/special/nanmax.h"
|
|
206
|
+
#include <stdio.h>
|
|
207
|
+
|
|
208
|
+
int main( void ) {
|
|
209
|
+
const double x[] = { 1.0, 0.45, -0.89, 0.0 / 0.0, -0.78, -0.22, 0.66, 0.11, -0.55, 0.0 };
|
|
210
|
+
const double y[] = { -0.22, 0.66, 0.0, -0.55, 0.33, 1.0, 0.0 / 0.0, 0.11, 0.45, -0.78 };
|
|
211
|
+
|
|
212
|
+
double v;
|
|
213
|
+
int i;
|
|
214
|
+
for ( i = 0; i < 10; i++ ) {
|
|
215
|
+
v = stdlib_base_nanmax( x[i], y[i] );
|
|
216
|
+
printf( "x[ %d ]: %lf, y[ %d ]: %lf, nanmax( x[ %d ], y[ %d ] ): %lf\n", i, x[ i ], i, y[ i ], i, i, v );
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
</section>
|
|
222
|
+
|
|
223
|
+
<!-- /.examples -->
|
|
224
|
+
|
|
225
|
+
</section>
|
|
226
|
+
|
|
227
|
+
<!-- /.c -->
|
|
228
|
+
|
|
105
229
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
106
230
|
|
|
107
231
|
<section class="related">
|
|
@@ -136,7 +260,7 @@ See [LICENSE][stdlib-license].
|
|
|
136
260
|
|
|
137
261
|
## Copyright
|
|
138
262
|
|
|
139
|
-
Copyright © 2016-
|
|
263
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
140
264
|
|
|
141
265
|
</section>
|
|
142
266
|
|
|
@@ -149,8 +273,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
149
273
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-nanmax.svg
|
|
150
274
|
[npm-url]: https://npmjs.org/package/@stdlib/math-base-special-nanmax
|
|
151
275
|
|
|
152
|
-
[test-image]: https://github.com/stdlib-js/math-base-special-nanmax/actions/workflows/test.yml/badge.svg?branch=v0.0
|
|
153
|
-
[test-url]: https://github.com/stdlib-js/math-base-special-nanmax/actions/workflows/test.yml?query=branch:v0.0
|
|
276
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-nanmax/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
277
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-nanmax/actions/workflows/test.yml?query=branch:v0.1.0
|
|
154
278
|
|
|
155
279
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-nanmax/main.svg
|
|
156
280
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-nanmax?branch=main
|
|
@@ -162,8 +286,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
162
286
|
|
|
163
287
|
-->
|
|
164
288
|
|
|
165
|
-
[chat-image]: https://img.shields.io/
|
|
166
|
-
[chat-url]: https://
|
|
289
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
290
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
167
291
|
|
|
168
292
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
169
293
|
|
|
@@ -181,7 +305,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
181
305
|
[branches-url]: https://github.com/stdlib-js/math-base-special-nanmax/blob/main/branches.md
|
|
182
306
|
|
|
183
307
|
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/math-base-special-nanmax/main/LICENSE
|
|
184
|
-
|
|
308
|
+
|
|
185
309
|
<!-- <related-links> -->
|
|
186
310
|
|
|
187
311
|
<!-- </related-links> -->
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
#ifndef STDLIB_MATH_BASE_SPECIAL_NANMAX_H
|
|
20
|
+
#define STDLIB_MATH_BASE_SPECIAL_NANMAX_H
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
24
|
+
*/
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
extern "C" {
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns the maximum value, ignoring NaN.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_nanmax( const double x, const double y );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_MATH_BASE_SPECIAL_NANMAX_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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 addon = require( './../src/addon.node' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns the maximum value, ignoring NaN.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - first number
|
|
33
|
+
* @param {number} y - second number
|
|
34
|
+
* @returns {number} maximum value
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var v = nanmax( 3.14, 4.2 );
|
|
38
|
+
* // returns 4.2
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var v = nanmax( 4.14, NaN );
|
|
42
|
+
* // returns 4.14
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var v = nanmax( NaN, NaN );
|
|
46
|
+
* // returns NaN
|
|
47
|
+
*/
|
|
48
|
+
function nanmax( x, y ) {
|
|
49
|
+
return addon( x, y );
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// EXPORTS //
|
|
54
|
+
|
|
55
|
+
module.exports = nanmax;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": {
|
|
3
|
+
"task": "build"
|
|
4
|
+
},
|
|
5
|
+
"fields": [
|
|
6
|
+
{
|
|
7
|
+
"field": "src",
|
|
8
|
+
"resolve": true,
|
|
9
|
+
"relative": true
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"field": "include",
|
|
13
|
+
"resolve": true,
|
|
14
|
+
"relative": true
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"field": "libraries",
|
|
18
|
+
"resolve": false,
|
|
19
|
+
"relative": false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"field": "libpath",
|
|
23
|
+
"resolve": true,
|
|
24
|
+
"relative": false
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"confs": [
|
|
28
|
+
{
|
|
29
|
+
"task": "build",
|
|
30
|
+
"src": [
|
|
31
|
+
"./src/main.c"
|
|
32
|
+
],
|
|
33
|
+
"include": [
|
|
34
|
+
"./include"
|
|
35
|
+
],
|
|
36
|
+
"libraries": [],
|
|
37
|
+
"libpath": [],
|
|
38
|
+
"dependencies": [
|
|
39
|
+
"@stdlib/math-base-napi-binary",
|
|
40
|
+
"@stdlib/math-base-assert-is-nan",
|
|
41
|
+
"@stdlib/math-base-special-max"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"task": "benchmark",
|
|
46
|
+
"src": [
|
|
47
|
+
"./src/main.c"
|
|
48
|
+
],
|
|
49
|
+
"include": [
|
|
50
|
+
"./include"
|
|
51
|
+
],
|
|
52
|
+
"libraries": [],
|
|
53
|
+
"libpath": [],
|
|
54
|
+
"dependencies": [
|
|
55
|
+
"@stdlib/math-base-assert-is-nan",
|
|
56
|
+
"@stdlib/math-base-special-max"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"task": "examples",
|
|
61
|
+
"src": [
|
|
62
|
+
"./src/main.c"
|
|
63
|
+
],
|
|
64
|
+
"include": [
|
|
65
|
+
"./include"
|
|
66
|
+
],
|
|
67
|
+
"libraries": [],
|
|
68
|
+
"libpath": [],
|
|
69
|
+
"dependencies": [
|
|
70
|
+
"@stdlib/math-base-assert-is-nan",
|
|
71
|
+
"@stdlib/math-base-special-max"
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-special-nanmax",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Return the maximum value, ignoring NaN.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"main": "./lib",
|
|
17
|
+
"gypfile": false,
|
|
17
18
|
"directories": {
|
|
18
19
|
"doc": "./docs",
|
|
20
|
+
"include": "./include",
|
|
19
21
|
"lib": "./lib",
|
|
22
|
+
"src": "./src",
|
|
20
23
|
"dist": "./dist"
|
|
21
24
|
},
|
|
22
25
|
"types": "./docs/types",
|
|
@@ -31,7 +34,9 @@
|
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
34
|
-
"@stdlib/math-base-
|
|
37
|
+
"@stdlib/math-base-napi-binary": "^0.3.1",
|
|
38
|
+
"@stdlib/math-base-special-max": "^0.3.0",
|
|
39
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {},
|
|
37
42
|
"engines": {
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
#include "stdlib/math/base/special/nanmax.h"
|
|
20
|
+
#include "stdlib/math/base/napi/binary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_nanmax )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
#include "stdlib/math/base/special/nanmax.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/max.h"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns the maximum value, ignoring NaN.
|
|
25
|
+
*
|
|
26
|
+
* @param x first number
|
|
27
|
+
* @param y second number
|
|
28
|
+
* @return maximum value
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* double v = stdlib_base_nanmax( 3.14, 4.2 );
|
|
32
|
+
* // returns 4.2
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* double v = stdlib_base_nanmax( 4.14, 0.0 / 0.0 );
|
|
36
|
+
* // returns 4.14
|
|
37
|
+
*/
|
|
38
|
+
double stdlib_base_nanmax( const double x, const double y ) {
|
|
39
|
+
if ( stdlib_base_is_nan( x ) ) {
|
|
40
|
+
return stdlib_base_is_nan( y ) ? 0.0 / 0.0 : y;
|
|
41
|
+
}
|
|
42
|
+
return stdlib_base_is_nan( y ) ? x : stdlib_base_max( x, y );
|
|
43
|
+
}
|