@stdlib/math-base-napi-quinary 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.
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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_NAPI_QUINARY_H
20
+ #define STDLIB_MATH_BASE_NAPI_QUINARY_H
21
+
22
+ #include <node_api.h>
23
+ #include <assert.h>
24
+
25
+ /**
26
+ * Macro for registering a Node-API module exporting an interface invoking a quinary function accepting and returning double-precision floating-point numbers.
27
+ *
28
+ * @param fcn quinary function
29
+ *
30
+ * @example
31
+ * static double add( const double x, const double y, const double z, const double w, const double u ) {
32
+ * return x + y + z + w + u;
33
+ * }
34
+ *
35
+ * // ...
36
+ *
37
+ * // Register a Node-API module:
38
+ * STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( add );
39
+ */
40
+ #define STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( fcn ) \
41
+ static napi_value stdlib_math_base_napi_ddddd_d_wrapper( \
42
+ napi_env env, \
43
+ napi_callback_info info \
44
+ ) { \
45
+ return stdlib_math_base_napi_ddddd_d( env, info, fcn ); \
46
+ }; \
47
+ static napi_value stdlib_math_base_napi_ddddd_d_init( \
48
+ napi_env env, \
49
+ napi_value exports \
50
+ ) { \
51
+ napi_value fcn; \
52
+ napi_status status = napi_create_function( \
53
+ env, \
54
+ "exports", \
55
+ NAPI_AUTO_LENGTH, \
56
+ stdlib_math_base_napi_ddddd_d_wrapper, \
57
+ NULL, \
58
+ &fcn \
59
+ ); \
60
+ assert( status == napi_ok ); \
61
+ return fcn; \
62
+ }; \
63
+ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_ddddd_d_init )
64
+
65
+ /**
66
+ * Macro for registering a Node-API module exporting an interface invoking a quinary function accepting and returning single-precision floating-point numbers.
67
+ *
68
+ * @param fcn quinary function
69
+ *
70
+ * @example
71
+ * static float addf( const float x, const float y, const float z, const float w, const float u ) {
72
+ * return x + y + z + w + u;
73
+ * }
74
+ *
75
+ * // ...
76
+ *
77
+ * // Register a Node-API module:
78
+ * STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( addf );
79
+ */
80
+ #define STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( fcn ) \
81
+ static napi_value stdlib_math_base_napi_fffff_f_wrapper( \
82
+ napi_env env, \
83
+ napi_callback_info info \
84
+ ) { \
85
+ return stdlib_math_base_napi_fffff_f( env, info, fcn ); \
86
+ }; \
87
+ static napi_value stdlib_math_base_napi_fffff_f_init( \
88
+ napi_env env, \
89
+ napi_value exports \
90
+ ) { \
91
+ napi_value fcn; \
92
+ napi_status status = napi_create_function( \
93
+ env, \
94
+ "exports", \
95
+ NAPI_AUTO_LENGTH, \
96
+ stdlib_math_base_napi_fffff_f_wrapper, \
97
+ NULL, \
98
+ &fcn \
99
+ ); \
100
+ assert( status == napi_ok ); \
101
+ return fcn; \
102
+ }; \
103
+ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_fffff_f_init )
104
+
105
+ /*
106
+ * If C++, prevent name mangling so that the compiler emits a quinary file having undecorated names, thus mirroring the behavior of a C compiler.
107
+ */
108
+ #ifdef __cplusplus
109
+ extern "C" {
110
+ #endif
111
+
112
+ /**
113
+ * Invokes a quinary function accepting and returning double-precision floating-point numbers.
114
+ */
115
+ napi_value stdlib_math_base_napi_ddddd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double, double, double, double ) );
116
+
117
+ /**
118
+ * Invokes a quinary function accepting and returning single-precision floating-point numbers.
119
+ */
120
+ napi_value stdlib_math_base_napi_fffff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float, float, float ) );
121
+
122
+ #ifdef __cplusplus
123
+ }
124
+ #endif
125
+
126
+ #endif // !STDLIB_MATH_BASE_NAPI_QUINARY_H
package/include.gypi ADDED
@@ -0,0 +1,53 @@
1
+ # @license Apache-2.0
2
+ #
3
+ # Copyright (c) 2023 The Stdlib Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # A GYP include file for building a Node.js native add-on.
18
+ #
19
+ # Main documentation:
20
+ #
21
+ # [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
22
+ # [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
23
+ {
24
+ # Define variables to be used throughout the configuration for all targets:
25
+ 'variables': {
26
+ # Source directory:
27
+ 'src_dir': './src',
28
+
29
+ # Include directories:
30
+ 'include_dirs': [
31
+ '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
32
+ ],
33
+
34
+ # Add-on destination directory:
35
+ 'addon_output_dir': './src',
36
+
37
+ # Source files:
38
+ 'src_files': [
39
+ '<(src_dir)/addon.c',
40
+ '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
41
+ ],
42
+
43
+ # Library dependencies:
44
+ 'libraries': [
45
+ '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
46
+ ],
47
+
48
+ # Library directories:
49
+ 'library_dirs': [
50
+ '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
51
+ ],
52
+ }, # end variables
53
+ }
package/lib/browser.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ // MAIN //
22
+
23
+ var headerDir = null;
24
+
25
+
26
+ // EXPORTS //
27
+
28
+ module.exports = headerDir;
package/lib/index.js ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ /**
22
+ * Absolute file path for the directory containing header files for C APIs.
23
+ *
24
+ * @module @stdlib/math-base-napi-quinary
25
+ *
26
+ * @example
27
+ * var headerDir = require( '@stdlib/math-base-napi-quinary' );
28
+ *
29
+ * console.log( headerDir );
30
+ */
31
+
32
+ // MODULES //
33
+
34
+ var main = require( './main.js' );
35
+
36
+
37
+ // EXPORTS //
38
+
39
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Absolute file path for the directory containing header files for C APIs.
30
+ *
31
+ * @name headerDir
32
+ * @constant
33
+ * @type {string}
34
+ */
35
+ var headerDir = resolve( __dirname, '..', 'include' );
36
+
37
+
38
+ // EXPORTS //
39
+
40
+ module.exports = headerDir;
package/lib/native.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ * Wrapper function exposing the C API to JavaScript.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {number} y - input value
34
+ * @param {number} z - input value
35
+ * @param {number} w - input value
36
+ * @param {number} u - input value
37
+ * @returns {number} result
38
+ *
39
+ * @example
40
+ * var y = wrapper( 3.14, 3.14, 3.14, 3.14, 31.4 );
41
+ * // returns <number>
42
+ */
43
+ function wrapper( x, y, z, w, u ) {
44
+ return addon( x, y, z, w, u );
45
+ }
46
+
47
+
48
+ // EXPORTS //
49
+
50
+ module.exports = wrapper;
package/manifest.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "options": {},
3
+ "fields": [
4
+ {
5
+ "field": "src",
6
+ "resolve": true,
7
+ "relative": true
8
+ },
9
+ {
10
+ "field": "include",
11
+ "resolve": true,
12
+ "relative": true
13
+ },
14
+ {
15
+ "field": "libraries",
16
+ "resolve": false,
17
+ "relative": false
18
+ },
19
+ {
20
+ "field": "libpath",
21
+ "resolve": true,
22
+ "relative": false
23
+ }
24
+ ],
25
+ "confs": [
26
+ {
27
+ "src": [
28
+ "./src/main.c"
29
+ ],
30
+ "include": [
31
+ "./include"
32
+ ],
33
+ "libraries": [],
34
+ "libpath": [],
35
+ "dependencies": []
36
+ }
37
+ ]
38
+ }
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@stdlib/math-base-napi-quinary",
3
+ "version": "0.1.0",
4
+ "description": "C APIs for registering a Node-API module exporting an interface for invoking a quinary numerical function.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "browser": "./lib/browser.js",
18
+ "gypfile": false,
19
+ "directories": {
20
+ "benchmark": "./benchmark",
21
+ "doc": "./docs",
22
+ "example": "./examples",
23
+ "include": "./include",
24
+ "lib": "./lib",
25
+ "src": "./src",
26
+ "test": "./test"
27
+ },
28
+ "types": "./docs/types",
29
+ "scripts": {
30
+ "test": "make test",
31
+ "test-cov": "make test-cov",
32
+ "examples": "make examples",
33
+ "benchmark": "make benchmark"
34
+ },
35
+ "homepage": "https://stdlib.io",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git://github.com/stdlib-js/math-base-napi-quinary.git"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/stdlib-js/stdlib/issues"
42
+ },
43
+ "dependencies": {
44
+ "@stdlib/utils-library-manifest": "^0.1.1"
45
+ },
46
+ "devDependencies": {
47
+ "@stdlib/assert-is-browser": "^0.1.1",
48
+ "@stdlib/bench": "^0.2.1",
49
+ "@stdlib/math-base-assert-is-nan": "^0.1.1",
50
+ "@stdlib/utils-try-require": "^0.1.1",
51
+ "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
52
+ "istanbul": "^0.4.1",
53
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
54
+ },
55
+ "engines": {
56
+ "node": ">=0.10.0",
57
+ "npm": ">2.7.0"
58
+ },
59
+ "os": [
60
+ "aix",
61
+ "darwin",
62
+ "freebsd",
63
+ "linux",
64
+ "macos",
65
+ "openbsd",
66
+ "sunos",
67
+ "win32",
68
+ "windows"
69
+ ],
70
+ "keywords": [
71
+ "stdlib",
72
+ "stdmath",
73
+ "mathematics",
74
+ "math",
75
+ "napi",
76
+ "n-api",
77
+ "node-api",
78
+ "addon",
79
+ "quinary",
80
+ "map",
81
+ "transform"
82
+ ],
83
+ "__stdlib__": {
84
+ "envs": {
85
+ "browser": false
86
+ }
87
+ },
88
+ "funding": {
89
+ "type": "opencollective",
90
+ "url": "https://opencollective.com/stdlib"
91
+ }
92
+ }
package/src/addon.c ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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/napi/quinary.h"
20
+
21
+ /**
22
+ * Adds double-precision floating-point numbers.
23
+ *
24
+ * @param x input value
25
+ * @param y input value
26
+ * @param z input value
27
+ * @param w input value
28
+ * @param u input value
29
+ * @return sum
30
+ */
31
+ static double add( const double x, const double y, const double z, const double w, const double u ) {
32
+ return x + y + z + w + u;
33
+ }
34
+
35
+ // cppcheck-suppress shadowFunction
36
+ STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( add )