@stdlib/number-float32-base-signbit 0.2.1 → 0.3.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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -29,7 +29,7 @@ limitations under the License.
29
29
  <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
30
  </details>
31
31
 
32
- # signbit
32
+ # signbitf
33
33
 
34
34
  [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
35
 
@@ -55,7 +55,7 @@ var signbitf = require( '@stdlib/number-float32-base-signbit' );
55
55
 
56
56
  #### signbitf( x )
57
57
 
58
- Returns a `boolean` indicating if the sign bit for a [single-precision floating-point number][ieee754] is on (`true`) or off (`false`).
58
+ Returns a boolean indicating if the sign bit for a [single-precision floating-point number][ieee754] is on (`true`) or off (`false`).
59
59
 
60
60
  ```javascript
61
61
  var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );
@@ -105,6 +105,94 @@ for ( i = 0; i < 100; i++ ) {
105
105
 
106
106
  <!-- /.examples -->
107
107
 
108
+ <!-- C interface documentation. -->
109
+
110
+ * * *
111
+
112
+ <section class="c">
113
+
114
+ ## C APIs
115
+
116
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
117
+
118
+ <section class="intro">
119
+
120
+ </section>
121
+
122
+ <!-- /.intro -->
123
+
124
+ <!-- C usage documentation. -->
125
+
126
+ <section class="usage">
127
+
128
+ ### Usage
129
+
130
+ ```c
131
+ #include "stdlib/number/float32/base/signbit.h"
132
+ ```
133
+
134
+ #### stdlib_base_float32_signbit( x )
135
+
136
+ Returns an integer indicating whether the sign bit for a single-precision floating-point number is on (`1`) or off (`0`).
137
+
138
+ ```c
139
+ #include <stdint.h>
140
+
141
+ int8_t out = stdlib_base_float32_signbit( 3.14f );
142
+ ```
143
+
144
+ The function accepts the following arguments:
145
+
146
+ - **x**: `[in] float` input value.
147
+
148
+ ```c
149
+ int8_t stdlib_base_float32_signbit( const float x );
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/number/float32/base/signbit.h"
172
+ #include <stdint.h>
173
+ #include <stdio.h>
174
+ #include <inttypes.h>
175
+
176
+ int main( void ) {
177
+ float x[] = { 3.14f, -3.14f, 0.0f, -0.0f, 4.0f, 1.0f, -1.0f, 1.0e38f, -1.0e38f };
178
+
179
+ int8_t out;
180
+ int i;
181
+ for ( i = 0; i < 9; i++ ) {
182
+ stdlib_base_float32_signbit( x[ i ], &out );
183
+ printf( "%f => signbit: %" PRId8 "\n", x[ i ], out );
184
+ }
185
+ }
186
+ ```
187
+
188
+ </section>
189
+
190
+ <!-- /.examples -->
191
+
192
+ </section>
193
+
194
+ <!-- /.c -->
195
+
108
196
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
109
197
 
110
198
  <section class="related">
@@ -145,7 +233,7 @@ See [LICENSE][stdlib-license].
145
233
 
146
234
  ## Copyright
147
235
 
148
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
236
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
149
237
 
150
238
  </section>
151
239
 
@@ -158,8 +246,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
158
246
  [npm-image]: http://img.shields.io/npm/v/@stdlib/number-float32-base-signbit.svg
159
247
  [npm-url]: https://npmjs.org/package/@stdlib/number-float32-base-signbit
160
248
 
161
- [test-image]: https://github.com/stdlib-js/number-float32-base-signbit/actions/workflows/test.yml/badge.svg?branch=v0.2.1
162
- [test-url]: https://github.com/stdlib-js/number-float32-base-signbit/actions/workflows/test.yml?query=branch:v0.2.1
249
+ [test-image]: https://github.com/stdlib-js/number-float32-base-signbit/actions/workflows/test.yml/badge.svg?branch=v0.3.0
250
+ [test-url]: https://github.com/stdlib-js/number-float32-base-signbit/actions/workflows/test.yml?query=branch:v0.3.0
163
251
 
164
252
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/number-float32-base-signbit/main.svg
165
253
  [coverage-url]: https://codecov.io/github/stdlib-js/number-float32-base-signbit?branch=main
@@ -171,8 +259,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
171
259
 
172
260
  -->
173
261
 
174
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
175
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
262
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
263
+ [chat-url]: https://stdlib.zulipchat.com
176
264
 
177
265
  [stdlib]: https://github.com/stdlib-js/stdlib
178
266
 
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar toWord = require( '@stdlib/number-float32-base-to-word' );\n\n\n// MAIN //\n\n/**\n* Returns a boolean indicating if the sign bit is on (true) or off (false).\n*\n* @param {number} x - single-precision floating-point number\n* @returns {boolean} boolean indicating if sign bit is on or off\n*\n* @example\n* var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );\n* var bool = signbitf( toFloat32( 4.0 ) );\n* // returns false\n*\n* @example\n* var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );\n* var bool = signbitf( toFloat32( -9.14e-34 ) );\n* // returns true\n*\n* @example\n* var bool = signbitf( 0.0 );\n* // returns false\n*\n* @example\n* var bool = signbitf( -0.0 );\n* // returns true\n*/\nfunction signbitf( x ) {\n\t// Convert `x` to an unsigned 32-bit integer corresponding to the value's IEEE 754 binary representation:\n\tvar w = toWord( x );\n\n\t// Shift off all bits which are not the sign bit and check if the sign bit is on:\n\treturn ( w >>> 31 ) ? true : false; // eslint-disable-line no-unneeded-ternary\n}\n\n\n// EXPORTS //\n\nmodule.exports = signbitf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a boolean indicating if the sign bit is on (true) or off (false).\n*\n* @module @stdlib/number-float32-base-signbit\n*\n* @example\n* var signbitf = require( '@stdlib/number-float32-base-signbit' );\n* var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );\n*\n* var bool = signbitf( toFloat32( 4.0 ) );\n* // returns false\n*\n* bool = signbitf( toFloat32( -9.14e-34 ) );\n* // returns true\n*\n* bool = signbitf( 0.0 );\n* // returns false\n*\n* bool = signbitf( -0.0 );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,qCAAsC,EA6B5D,SAASC,EAAUC,EAAI,CAEtB,IAAIC,EAAIH,EAAQE,CAAE,EAGlB,MAAS,GAAAC,IAAM,GAChB,CAKAJ,EAAO,QAAUE,IClBjB,IAAIG,EAAO,IAKX,OAAO,QAAUA",
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar toWord = require( '@stdlib/number-float32-base-to-word' );\n\n\n// MAIN //\n\n/**\n* Returns a boolean indicating if the sign bit is on (true) or off (false).\n*\n* @param {number} x - single-precision floating-point number\n* @returns {boolean} boolean indicating if sign bit is on or off\n*\n* @example\n* var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );\n*\n* var bool = signbitf( toFloat32( 4.0 ) );\n* // returns false\n*\n* @example\n* var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );\n*\n* var bool = signbitf( toFloat32( -9.14e-34 ) );\n* // returns true\n*\n* @example\n* var bool = signbitf( 0.0 );\n* // returns false\n*\n* @example\n* var bool = signbitf( -0.0 );\n* // returns true\n*/\nfunction signbitf( x ) {\n\t// Convert `x` to an unsigned 32-bit integer corresponding to the value's IEEE 754 binary representation:\n\tvar w = toWord( x );\n\n\t// Shift off all bits which are not the sign bit and check if the sign bit is on:\n\treturn ( w >>> 31 ) ? true : false; // eslint-disable-line no-unneeded-ternary\n}\n\n\n// EXPORTS //\n\nmodule.exports = signbitf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Return a boolean indicating if the sign bit is on (true) or off (false).\n*\n* @module @stdlib/number-float32-base-signbit\n*\n* @example\n* var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );\n* var signbitf = require( '@stdlib/number-float32-base-signbit' );\n*\n* var bool = signbitf( toFloat32( 4.0 ) );\n* // returns false\n*\n* bool = signbitf( toFloat32( -9.14e-34 ) );\n* // returns true\n*\n* bool = signbitf( 0.0 );\n* // returns false\n*\n* bool = signbitf( -0.0 );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,qCAAsC,EA+B5D,SAASC,EAAUC,EAAI,CAEtB,IAAIC,EAAIH,EAAQE,CAAE,EAGlB,MAAS,GAAAC,IAAM,GAChB,CAKAJ,EAAO,QAAUE,ICpBjB,IAAIG,EAAO,IAKX,OAAO,QAAUA",
6
6
  "names": ["require_main", "__commonJSMin", "exports", "module", "toWord", "signbitf", "x", "w", "main"]
7
7
  }
@@ -26,11 +26,13 @@
26
26
  *
27
27
  * @example
28
28
  * var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );
29
+ *
29
30
  * var bool = signbitf( toFloat32( 4.0 ) );
30
31
  * // returns false
31
32
  *
32
33
  * @example
33
34
  * var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );
35
+ *
34
36
  * var bool = signbitf( toFloat32( -9.14e-34 ) );
35
37
  * // returns true
36
38
  *
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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_NUMBER_FLOAT32_BASE_SIGNBIT_H
20
+ #define STDLIB_NUMBER_FLOAT32_BASE_SIGNBIT_H
21
+
22
+ #include <stdint.h>
23
+
24
+ /*
25
+ * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
26
+ */
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ /**
32
+ * Returns an integer indicating whether the sign bit for a single-precision floating-point number is on (`1`) or off (`0`).
33
+ */
34
+ int8_t stdlib_base_float32_signbit( const float x );
35
+
36
+ #ifdef __cplusplus
37
+ }
38
+ #endif
39
+
40
+ #endif // !STDLIB_NUMBER_FLOAT32_BASE_SIGNBIT_H
package/lib/index.js CHANGED
@@ -24,8 +24,8 @@
24
24
  * @module @stdlib/number-float32-base-signbit
25
25
  *
26
26
  * @example
27
- * var signbitf = require( '@stdlib/number-float32-base-signbit' );
28
27
  * var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );
28
+ * var signbitf = require( '@stdlib/number-float32-base-signbit' );
29
29
  *
30
30
  * var bool = signbitf( toFloat32( 4.0 ) );
31
31
  * // returns false
package/lib/main.js CHANGED
@@ -33,11 +33,13 @@ var toWord = require( '@stdlib/number-float32-base-to-word' );
33
33
  *
34
34
  * @example
35
35
  * var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );
36
+ *
36
37
  * var bool = signbitf( toFloat32( 4.0 ) );
37
38
  * // returns false
38
39
  *
39
40
  * @example
40
41
  * var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );
42
+ *
41
43
  * var bool = signbitf( toFloat32( -9.14e-34 ) );
42
44
  * // returns true
43
45
  *
package/lib/native.js ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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 Boolean = require( '@stdlib/boolean-ctor' );
24
+ var addon = require( './../src/addon.node' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Returns a boolean indicating if the sign bit is on (true) or off (false).
31
+ *
32
+ * @private
33
+ * @param {number} x - input value
34
+ * @returns {boolean} boolean indicating if sign bit is on or off
35
+ *
36
+ * @example
37
+ * var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );
38
+ *
39
+ * var bool = signbitf( toFloat32( 4.0 ) );
40
+ * // returns false
41
+ *
42
+ * @example
43
+ * var toFloat32 = require( '@stdlib/number-float64-base-to-float32' );
44
+ *
45
+ * var bool = signbitf( toFloat32( -9.14e-34 ) );
46
+ * // returns true
47
+ *
48
+ * @example
49
+ * var bool = signbitf( 0.0 );
50
+ * // returns false
51
+ *
52
+ * @example
53
+ * var bool = signbitf( -0.0 );
54
+ * // returns true
55
+ */
56
+ function signbitf( x ) {
57
+ return Boolean( addon( x ) );
58
+ }
59
+
60
+
61
+ // EXPORTS //
62
+
63
+ module.exports = signbitf;
package/manifest.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "options": {
3
+ "task": "build",
4
+ "wasm": false
5
+ },
6
+ "fields": [
7
+ {
8
+ "field": "src",
9
+ "resolve": true,
10
+ "relative": true
11
+ },
12
+ {
13
+ "field": "include",
14
+ "resolve": true,
15
+ "relative": true
16
+ },
17
+ {
18
+ "field": "libraries",
19
+ "resolve": false,
20
+ "relative": false
21
+ },
22
+ {
23
+ "field": "libpath",
24
+ "resolve": true,
25
+ "relative": false
26
+ }
27
+ ],
28
+ "confs": [
29
+ {
30
+ "task": "build",
31
+ "wasm": false,
32
+ "src": [
33
+ "./src/main.c"
34
+ ],
35
+ "include": [
36
+ "./include"
37
+ ],
38
+ "libraries": [],
39
+ "libpath": [],
40
+ "dependencies": [
41
+ "@stdlib/number-float32-base-to-word"
42
+ ]
43
+ },
44
+ {
45
+ "task": "benchmark",
46
+ "wasm": false,
47
+ "src": [
48
+ "./src/main.c"
49
+ ],
50
+ "include": [
51
+ "./include"
52
+ ],
53
+ "libraries": [],
54
+ "libpath": [],
55
+ "dependencies": [
56
+ "@stdlib/number-float32-base-to-word"
57
+ ]
58
+ },
59
+ {
60
+ "task": "examples",
61
+ "wasm": false,
62
+ "src": [
63
+ "./src/main.c"
64
+ ],
65
+ "include": [
66
+ "./include"
67
+ ],
68
+ "libraries": [],
69
+ "libpath": [],
70
+ "dependencies": [
71
+ "@stdlib/number-float32-base-to-word"
72
+ ]
73
+ }
74
+ ]
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/number-float32-base-signbit",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Return a boolean indicating if the sign bit for a single-precision floating-point number is on (true) or off (false).",
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",
@@ -30,7 +33,8 @@
30
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
34
  },
32
35
  "dependencies": {
33
- "@stdlib/number-float32-base-to-word": "^0.2.1"
36
+ "@stdlib/number-float32-base-to-word": "^0.2.2",
37
+ "@stdlib/utils-library-manifest": "^0.2.3"
34
38
  },
35
39
  "devDependencies": {},
36
40
  "engines": {
package/src/addon.c ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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/number/float32/base/signbit.h"
20
+ #include <node_api.h>
21
+ #include <stdint.h>
22
+ #include <stdbool.h>
23
+ #include <assert.h>
24
+
25
+ /**
26
+ * Receives JavaScript callback invocation data.
27
+ *
28
+ * @param env environment under which the function is invoked
29
+ * @param info callback data
30
+ * @return Node-API value
31
+ */
32
+ static napi_value addon( napi_env env, napi_callback_info info ) {
33
+ napi_status status;
34
+
35
+ // Get callback arguments:
36
+ size_t argc = 1;
37
+ napi_value argv[ 1 ];
38
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
39
+ assert( status == napi_ok );
40
+
41
+ // Check whether we were provided the correct number of arguments:
42
+ if ( argc < 1 ) {
43
+ status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
44
+ assert( status == napi_ok );
45
+ return NULL;
46
+ }
47
+ if ( argc > 1 ) {
48
+ status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
49
+ assert( status == napi_ok );
50
+ return NULL;
51
+ }
52
+
53
+ napi_valuetype vtype0;
54
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
55
+ assert( status == napi_ok );
56
+ if ( vtype0 != napi_number ) {
57
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
58
+ assert( status == napi_ok );
59
+ return NULL;
60
+ }
61
+
62
+ double value;
63
+ status = napi_get_value_double( env, argv[ 0 ], &value );
64
+ assert( status == napi_ok );
65
+
66
+ int8_t out = stdlib_base_float32_signbit( (float)value );
67
+
68
+ napi_value v;
69
+ status = napi_create_int32( env, (int8_t)out, &v );
70
+ assert( status == napi_ok );
71
+
72
+ return v;
73
+ }
74
+
75
+ /**
76
+ * Initializes a Node-API module.
77
+ *
78
+ * @param env environment under which the function is invoked
79
+ * @param exports exports object
80
+ * @return main export
81
+ */
82
+ static napi_value init( napi_env env, napi_value exports ) {
83
+ napi_value fcn;
84
+ napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
85
+ assert( status == napi_ok );
86
+ return fcn;
87
+ }
88
+
89
+ NAPI_MODULE( NODE_GYP_MODULE_NAME, init )
package/src/main.c ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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/number/float32/base/signbit.h"
20
+ #include "stdlib/number/float32/base/to_word.h"
21
+ #include <stdint.h>
22
+
23
+ /**
24
+ * Returns an integer indicating whether the sign bit for a single-precision floating-point number is on (`1`) or off (`0`).
25
+ *
26
+ * @param x input value
27
+ * @return result
28
+ *
29
+ * @example
30
+ * #include <stdint.h>
31
+ *
32
+ * int8_t out = stdlib_base_float32_signbit( 3.14f );
33
+ */
34
+ int8_t stdlib_base_float32_signbit( const float x ) {
35
+ uint32_t w;
36
+
37
+ // Convert the floating-point value to a word (unsigned 32-bit integer) containing the exponent and sign:
38
+ stdlib_base_float32_to_word( x, &w );
39
+
40
+ // Shift off all bits which are not the sign bit and check if the sign bit is on:
41
+ return (int8_t)( w >> 31 );
42
+ }