From 84c445b51d37635bdeedf74bab91aa5712e5207a Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 3 Dec 2025 18:43:06 +0530 Subject: [PATCH 1/4] feat: add constants/float16/sign-mask --- .../constants/float16/sign-mask/README.md | 169 ++++++++++++++++++ .../constants/float16/sign-mask/docs/repl.txt | 14 ++ .../float16/sign-mask/docs/types/index.d.ts | 33 ++++ .../float16/sign-mask/docs/types/test.ts | 28 +++ .../float16/sign-mask/examples/index.js | 37 ++++ .../stdlib/constants/float16/sign_mask.h | 27 +++ .../constants/float16/sign-mask/lib/index.js | 56 ++++++ .../constants/float16/sign-mask/manifest.json | 36 ++++ .../constants/float16/sign-mask/package.json | 68 +++++++ .../constants/float16/sign-mask/test/test.js | 52 ++++++ 10 files changed, 520 insertions(+) create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/README.md create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/examples/index.js create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/include/stdlib/constants/float16/sign_mask.h create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/lib/index.js create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/manifest.json create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/package.json create mode 100644 lib/node_modules/@stdlib/constants/float16/sign-mask/test/test.js diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/README.md b/lib/node_modules/@stdlib/constants/float16/sign-mask/README.md new file mode 100644 index 000000000000..e48aa0aa1e21 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/README.md @@ -0,0 +1,169 @@ + + +# FLOAT16_SIGN_MASK + +> Mask for the sign bit of a [half-precision floating-point number][ieee754]. + +
+ +## Usage + + + +```javascript +var FLOAT16_SIGN_MASK = require( '@stdlib/constants/float16/sign-mask' ); +``` + +#### FLOAT16_SIGN_MASK + +Mask for the sign bit of a [half-precision floating-point number][ieee754]. + + + +```javascript +// 0x8000 = 32768 => 1 00000 0000000000 +var bool = ( FLOAT16_SIGN_MASK === 0x8000 ); +// returns true +``` + +
+ + + +
+ +## Notes + +- The higher order word of a [half-precision floating-point number][ieee754] is a 16-bit integer containing the more significant bits which include the exponent and sign. + +
+ + + +
+ +## Examples + + + + + +```javascript +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var fromWord = require( '@stdlib/number/float16/base/from-word' ); +var FLOAT16_SIGN_MASK = require( '@stdlib/constants/float16/sign-mask' ); + +var x = -11.5; +var w = toWord( x ); // 1 10010 0111000000 +// returns 51648 + +// Mask off all bits except for the sign bit: +var out = (w & FLOAT16_SIGN_MASK)>>>0; // 1 00000 0000000000 +// returns 32768 + +// Turn off the sign bit and leave other bits unchanged: +out = w & (~FLOAT16_SIGN_MASK); // 0 10010 0111000000 +// returns 18880 + +// Generate a new value: +out = fromWord( out ); +// returns 11.5 +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/constants/float16/sign_mask.h" +``` + +#### STDLIB_CONSTANT_FLOAT16_SIGN_MASK + +Macro for the mask for the sign bit of a [half-precision floating-point number][ieee754]. + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/repl.txt b/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/repl.txt new file mode 100644 index 000000000000..4bbb285ce0fd --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/repl.txt @@ -0,0 +1,14 @@ + +{{alias}} + Mask for the sign bit of a half-precision floating-point number. + + Examples + -------- + > {{alias}} + 32768 + > {{alias:@stdlib/number/uint16/base/to-binary-string}}( {{alias}} ) + '1000000000000000' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/types/index.d.ts b/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/types/index.d.ts new file mode 100644 index 000000000000..71f6785a0550 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/types/index.d.ts @@ -0,0 +1,33 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Mask for the sign bit of a half-precision floating-point number. +* +* @example +* var mask = FLOAT16_SIGN_MASK; +* // returns 32768 +*/ +declare const FLOAT16_SIGN_MASK: number; + + +// EXPORTS // + +export = FLOAT16_SIGN_MASK; diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/types/test.ts b/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/types/test.ts new file mode 100644 index 000000000000..fb7b4f1ded5e --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/docs/types/test.ts @@ -0,0 +1,28 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import FLOAT16_SIGN_MASK = require( './index' ); + + +// TESTS // + +// The export is a number... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + FLOAT16_SIGN_MASK; // $ExpectType number +} diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/examples/index.js b/lib/node_modules/@stdlib/constants/float16/sign-mask/examples/index.js new file mode 100644 index 000000000000..60a52b38eb5a --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/examples/index.js @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var fromWord = require( '@stdlib/number/float16/base/from-word' ); +var toBinaryString = require( '@stdlib/number/uint16/base/to-binary-string' ); +var FLOAT16_SIGN_MASK = require( './../lib' ); + +var x = -11.5; +var w = toWord( x ); +console.log( 'Word: %s', toBinaryString( w ) ); + +var out = (w & FLOAT16_SIGN_MASK)>>>0; +console.log( 'Isolate sign bits: %s', toBinaryString( out ) ); + +out = w & (~FLOAT16_SIGN_MASK); +console.log( 'Turn off sign bits: %s', toBinaryString( out ) ); + +out = fromWord( out ); +console.log( 'Value: %d', out ); diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/include/stdlib/constants/float16/sign_mask.h b/lib/node_modules/@stdlib/constants/float16/sign-mask/include/stdlib/constants/float16/sign_mask.h new file mode 100644 index 000000000000..870f74d5cfc2 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/include/stdlib/constants/float16/sign_mask.h @@ -0,0 +1,27 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef STDLIB_CONSTANTS_FLOAT16_SIGN_MASK_H +#define STDLIB_CONSTANTS_FLOAT16_SIGN_MASK_H + +/** +* Macro for the mask for the sign bit of a half-precision floating-point number. +*/ +#define STDLIB_CONSTANT_FLOAT16_SIGN_MASK 0x8000 + +#endif // !STDLIB_CONSTANTS_FLOAT16_SIGN_MASK_H diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/lib/index.js b/lib/node_modules/@stdlib/constants/float16/sign-mask/lib/index.js new file mode 100644 index 000000000000..509063b7f983 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/lib/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Mask for the sign bit of a half-precision floating-point number. +* +* @module @stdlib/constants/float16/sign-mask +* @type {uinteger16} +* +* @example +* var FLOAT16_SIGN_MASK = require( '@stdlib/constants/float16/sign-mask' ); +* // returns 32768 +*/ + + +// MAIN // + +/** +* Mask for the sign bit of a half-precision floating-point number. +* +* ## Notes +* +* The mask for the sign bit of a half-precision floating-point number is an unsigned 16-bit integer with the value \\( 32768 \\), which corresponds to the bit sequence +* +* ```binarystring +* 1 00000 0000000000 +* ``` +* +* @constant +* @type {uinteger16} +* @default 0x8000 +* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985} +*/ +var FLOAT16_SIGN_MASK = 0x8000>>>0; + + +// EXPORTS // + +module.exports = FLOAT16_SIGN_MASK; diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/manifest.json b/lib/node_modules/@stdlib/constants/float16/sign-mask/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/package.json b/lib/node_modules/@stdlib/constants/float16/sign-mask/package.json new file mode 100644 index 000000000000..3bb3315a0763 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/constants/float16/sign-mask", + "version": "0.0.0", + "description": "Mask for the sign bit of a half-precision floating-point number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "constant", + "const", + "mathematics", + "math", + "float", + "float16", + "16bit", + "floating-point", + "ieee754", + "mask", + "sign", + "bits", + "word" + ] +} diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/test/test.js b/lib/node_modules/@stdlib/constants/float16/sign-mask/test/test.js new file mode 100644 index 000000000000..141ac10cb902 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/test/test.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toBinaryString = require( '@stdlib/number/uint16/base/to-binary-string' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var FLOAT16_SIGN_MASK = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a number', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof FLOAT16_SIGN_MASK, 'number', 'main export is a number' ); + t.end(); +}); + +tape( 'the exported value can be used to mask off all bits except for the sign bit', function test( t ) { + var expected; + var actual; + var hi; + var x; + + x = -33.8; + hi = toWord( x ); // 53306 => 1 10100 0000111010 + + actual = (hi & FLOAT16_SIGN_MASK)>>>0; // 32768 => 1 00000 0000000000 + expected = '1000000000000000'; + + t.strictEqual( toBinaryString( actual ), expected ); + + t.end(); +}); From 8744aa53760751b858411346bcb62fdeba5f7065 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 3 Dec 2025 22:05:39 -0800 Subject: [PATCH 2/4] test: rename variable Signed-off-by: Athan --- .../@stdlib/constants/float16/sign-mask/test/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/test/test.js b/lib/node_modules/@stdlib/constants/float16/sign-mask/test/test.js index 141ac10cb902..40fab45f5d2a 100644 --- a/lib/node_modules/@stdlib/constants/float16/sign-mask/test/test.js +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/test/test.js @@ -37,13 +37,13 @@ tape( 'main export is a number', function test( t ) { tape( 'the exported value can be used to mask off all bits except for the sign bit', function test( t ) { var expected; var actual; - var hi; + var w; var x; x = -33.8; - hi = toWord( x ); // 53306 => 1 10100 0000111010 + w = toWord( x ); // 53306 => 1 10100 0000111010 - actual = (hi & FLOAT16_SIGN_MASK)>>>0; // 32768 => 1 00000 0000000000 + actual = (w & FLOAT16_SIGN_MASK)>>>0; // 32768 => 1 00000 0000000000 expected = '1000000000000000'; t.strictEqual( toBinaryString( actual ), expected ); From 023ae25778ce3d0762bb7da6c710171295300aa7 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 3 Dec 2025 22:06:18 -0800 Subject: [PATCH 3/4] docs: update example Signed-off-by: Athan --- .../@stdlib/constants/float16/sign-mask/examples/index.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/examples/index.js b/lib/node_modules/@stdlib/constants/float16/sign-mask/examples/index.js index 60a52b38eb5a..a1be3e82f76c 100644 --- a/lib/node_modules/@stdlib/constants/float16/sign-mask/examples/index.js +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/examples/index.js @@ -19,7 +19,6 @@ 'use strict'; var toWord = require( '@stdlib/number/float16/base/to-word' ); -var fromWord = require( '@stdlib/number/float16/base/from-word' ); var toBinaryString = require( '@stdlib/number/uint16/base/to-binary-string' ); var FLOAT16_SIGN_MASK = require( './../lib' ); @@ -32,6 +31,3 @@ console.log( 'Isolate sign bits: %s', toBinaryString( out ) ); out = w & (~FLOAT16_SIGN_MASK); console.log( 'Turn off sign bits: %s', toBinaryString( out ) ); - -out = fromWord( out ); -console.log( 'Value: %d', out ); From e09f384820528a51a17100b0e9b8830f4637ce17 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 3 Dec 2025 22:07:03 -0800 Subject: [PATCH 4/4] docs: update example and remove note Signed-off-by: Athan --- .../@stdlib/constants/float16/sign-mask/README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/node_modules/@stdlib/constants/float16/sign-mask/README.md b/lib/node_modules/@stdlib/constants/float16/sign-mask/README.md index e48aa0aa1e21..77d3e20998c8 100644 --- a/lib/node_modules/@stdlib/constants/float16/sign-mask/README.md +++ b/lib/node_modules/@stdlib/constants/float16/sign-mask/README.md @@ -50,10 +50,6 @@ var bool = ( FLOAT16_SIGN_MASK === 0x8000 );
-## Notes - -- The higher order word of a [half-precision floating-point number][ieee754] is a 16-bit integer containing the more significant bits which include the exponent and sign. -
@@ -68,7 +64,6 @@ var bool = ( FLOAT16_SIGN_MASK === 0x8000 ); ```javascript var toWord = require( '@stdlib/number/float16/base/to-word' ); -var fromWord = require( '@stdlib/number/float16/base/from-word' ); var FLOAT16_SIGN_MASK = require( '@stdlib/constants/float16/sign-mask' ); var x = -11.5; @@ -82,10 +77,6 @@ var out = (w & FLOAT16_SIGN_MASK)>>>0; // 1 00000 0000000000 // Turn off the sign bit and leave other bits unchanged: out = w & (~FLOAT16_SIGN_MASK); // 0 10010 0111000000 // returns 18880 - -// Generate a new value: -out = fromWord( out ); -// returns 11.5 ```