From b0c2f17eee5fd08f07170f3abfeeb147b3fd9d5d Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Thu, 18 Dec 2025 09:10:43 +0530 Subject: [PATCH 1/4] feat: add @stdlib/constants/float16/abs-mask --- .../constants/float16/abs-mask/README.md | 123 ++++++++++++++++++ .../constants/float16/abs-mask/docs/repl.txt | 12 ++ .../float16/abs-mask/docs/types/index.d.ts | 33 +++++ .../float16/abs-mask/docs/types/test.ts | 28 ++++ .../float16/abs-mask/examples/index.js | 30 +++++ .../constants/float16/abs-mask/lib/index.js | 56 ++++++++ .../constants/float16/abs-mask/package.json | 66 ++++++++++ .../constants/float16/abs-mask/test/test.js | 43 ++++++ 8 files changed, 391 insertions(+) create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/README.md create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/package.json create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/README.md b/lib/node_modules/@stdlib/constants/float16/abs-mask/README.md new file mode 100644 index 000000000000..47cbe07541d2 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/README.md @@ -0,0 +1,123 @@ + + +# FLOAT16_ABS_MASK + +> Mask for excluding the sign bit of a [half-precision floating-point number][ieee754]. + +
+ +## Usage + +```javascript +var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' ); +``` + +#### FLOAT16_ABS_MASK + +Mask for excluding the sign bit of a [half-precision floating-point number][ieee754]. + +```javascript +// 0x7fff = 32767 => 0 11111 1111111111 +var bool = ( FLOAT16_ABS_MASK === 0x7fff ); +// returns true +``` + +
+ + + +
+ +## Notes + +A [half-precision floating-point number][ieee754] has the following format: + +```text +1 11111 1111111111 +``` + +where the first bit is the sign bit, the next 5 bits are the exponent, and the last 10 bits are the significand (mantissa). The mask `0x7fff` sets the sign bit to `0`, effectively clearing it while preserving all other bits. + +
+ + + +
+ +## Examples + + + +```javascript +var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' ); + +// Example: The bitmask in binary +console.log( FLOAT16_ABS_MASK.toString( 2 ) ); +// => '111111111111111' + +// Example: The bitmask as a decimal +console.log( FLOAT16_ABS_MASK ); +// => 32767 + +// Example: The bitmask in hexadecimal +console.log( '0x' + FLOAT16_ABS_MASK.toString( 16 ) ); +// => '0x7fff' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt b/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt new file mode 100644 index 000000000000..a571b9eea5dd --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt @@ -0,0 +1,12 @@ + +{{alias}} + Mask for excluding the sign bit of a half-precision floating-point number. + + Examples + -------- + > {{alias}} + 32767 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/index.d.ts b/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/index.d.ts new file mode 100644 index 000000000000..9367084bf48b --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/abs-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 excluding the sign bit of a half-precision floating-point number. +* +* @example +* var val = FLOAT16_ABS_MASK; +* // returns 32767 +*/ +declare const FLOAT16_ABS_MASK: number; + + +// EXPORTS // + +export = FLOAT16_ABS_MASK; diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/test.ts b/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/test.ts new file mode 100644 index 000000000000..18d6bcab7d8f --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/abs-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_ABS_MASK = require( './index' ); + + +// TESTS // + +// The export is a number... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + FLOAT16_ABS_MASK; // $ExpectType number +} diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js b/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js new file mode 100644 index 000000000000..6adfa552fee0 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 FLOAT16_ABS_MASK = require( './../lib' ); + +console.log( 'Decimal: ' + FLOAT16_ABS_MASK ); +// => Decimal: 32767 + +console.log( 'Hexadecimal: 0x' + FLOAT16_ABS_MASK.toString( 16 ) ); +// => Hexadecimal: 0x7fff + +console.log( 'Binary: 0b' + FLOAT16_ABS_MASK.toString( 2 ) ); +// => Binary: 0b111111111111111 diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js b/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js new file mode 100644 index 000000000000..202d489fcbe9 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/abs-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 excluding the sign bit of a half-precision floating-point number. +* +* @module @stdlib/constants/float16/abs-mask +* @type {uinteger16} +* +* @example +* var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' ); +* // returns 32767 +*/ + + +// MAIN // + +/** +* Mask for excluding the sign bit of a half-precision floating-point number. +* +* ## Notes +* +* The mask for excluding the sign bit of a half-precision floating-point number is an unsigned 16-bit integer with the value \\( 32767 \\), which corresponds to the bit sequence +* +* ```binarystring +* 0 11111 1111111111 +* ``` +* +* @constant +* @type {uinteger16} +* @default 0x7fff +* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985} +*/ +var FLOAT16_ABS_MASK = 0x7fff|0; + + +// EXPORTS // + +module.exports = FLOAT16_ABS_MASK; diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/package.json b/lib/node_modules/@stdlib/constants/float16/abs-mask/package.json new file mode 100644 index 000000000000..547182966ead --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/constants/float16/abs-mask", + "version": "0.0.0", + "description": "Half-precision floating-point absolute value bitmask.", + "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", + "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", + "mask", + "abs", + "absolute", + "bitmask", + "ieee754", + "float", + "floating-point", + "float16" + ] +} diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js b/lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js new file mode 100644 index 000000000000..63c95305010b --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js @@ -0,0 +1,43 @@ +/** +* @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 FLOAT16_ABS_MASK = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a number', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof FLOAT16_ABS_MASK, 'number', 'main export is a number' ); + t.end(); +}); + +tape( 'the exported value equals 32767', function test( t ) { + t.strictEqual( FLOAT16_ABS_MASK, 32767, 'equals 32767' ); + t.end(); +}); + +tape( 'the exported value equals 0x7fff', function test( t ) { + t.strictEqual( FLOAT16_ABS_MASK, 0x7fff, 'equals 0x7fff' ); + t.end(); +}); From 99f3ef70a29d77bb8547bc8a6641367c87f64e6c Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Thu, 18 Dec 2025 09:19:30 +0530 Subject: [PATCH 2/4] fix of linting errors --- .../@stdlib/constants/float16/abs-mask/examples/index.js | 6 +++--- .../@stdlib/constants/float16/abs-mask/lib/index.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js b/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js index 6adfa552fee0..0ac639d96db1 100644 --- a/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js @@ -21,10 +21,10 @@ var FLOAT16_ABS_MASK = require( './../lib' ); console.log( 'Decimal: ' + FLOAT16_ABS_MASK ); -// => Decimal: 32767 +// => 'Decimal: 32767' console.log( 'Hexadecimal: 0x' + FLOAT16_ABS_MASK.toString( 16 ) ); -// => Hexadecimal: 0x7fff +// => 'Hexadecimal: 0x7fff' console.log( 'Binary: 0b' + FLOAT16_ABS_MASK.toString( 2 ) ); -// => Binary: 0b111111111111111 +// => 'Binary: 0b111111111111111' diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js b/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js index 202d489fcbe9..4576f61663eb 100644 --- a/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js @@ -22,7 +22,7 @@ * Mask for excluding the sign bit of a half-precision floating-point number. * * @module @stdlib/constants/float16/abs-mask -* @type {uinteger16} +* @type {number} * * @example * var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' ); @@ -44,7 +44,7 @@ * ``` * * @constant -* @type {uinteger16} +* @type {number} * @default 0x7fff * @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985} */ From 1042c079995f45d5359959857b246bf5c353c879 Mon Sep 17 00:00:00 2001 From: Aman Singh Date: Fri, 19 Dec 2025 08:04:51 +0530 Subject: [PATCH 3/4] addition of C header,manifest file and little changes --- .../constants/float16/abs-mask/README.md | 54 +++++++++++++++++++ .../stdlib/constants/float16/abs_mask.h | 27 ++++++++++ .../constants/float16/abs-mask/manifest.json | 36 +++++++++++++ .../constants/float16/abs-mask/package.json | 16 +++--- 4 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/include/stdlib/constants/float16/abs_mask.h create mode 100644 lib/node_modules/@stdlib/constants/float16/abs-mask/manifest.json diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/README.md b/lib/node_modules/@stdlib/constants/float16/abs-mask/README.md index 47cbe07541d2..4af533b8200d 100644 --- a/lib/node_modules/@stdlib/constants/float16/abs-mask/README.md +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/README.md @@ -86,6 +86,60 @@ console.log( '0x' + FLOAT16_ABS_MASK.toString( 16 ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/constants/float16/abs_mask.h" +``` + +#### STDLIB_CONSTANT_FLOAT16_ABS_MASK + +Macro for the mask for excluding the sign bit of a [half-precision floating-point number][ieee754]. + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + @@ -144,14 +137,6 @@ Macro for the mask for excluding the sign bit of a [half-precision floating-poin @@ -164,12 +149,6 @@ Macro for the mask for excluding the sign bit of a [half-precision floating-poin -[@stdlib/constants/float16/exponent-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/exponent-mask - -[@stdlib/constants/float16/sign-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/sign-mask - -[@stdlib/constants/float16/significand-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/significand-mask - diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt b/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt index a571b9eea5dd..fe6213b80f2b 100644 --- a/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt @@ -6,6 +6,8 @@ -------- > {{alias}} 32767 + > {{alias:@stdlib/number/uint16/base/to-binary-string}}( {{alias}} ) + '0111111111111111' See Also -------- diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/index.d.ts b/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/index.d.ts index 9367084bf48b..b9c456f40ff1 100644 --- a/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/index.d.ts @@ -22,7 +22,7 @@ * Mask for excluding the sign bit of a half-precision floating-point number. * * @example -* var val = FLOAT16_ABS_MASK; +* var mask = FLOAT16_ABS_MASK; * // returns 32767 */ declare const FLOAT16_ABS_MASK: number; diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js b/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js index 0ac639d96db1..20524c975681 100644 --- a/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js @@ -18,13 +18,17 @@ '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/uint32/base/to-binary-string' ); var FLOAT16_ABS_MASK = require( './../lib' ); -console.log( 'Decimal: ' + FLOAT16_ABS_MASK ); -// => 'Decimal: 32767' +var x = -11.5; +var w = toWord( x ); +console.log( 'Word: %s', toBinaryString( w ) ); -console.log( 'Hexadecimal: 0x' + FLOAT16_ABS_MASK.toString( 16 ) ); -// => 'Hexadecimal: 0x7fff' +var out = w & FLOAT16_ABS_MASK; +console.log( 'Turn off sign bits: %s', toBinaryString( out ) ); -console.log( 'Binary: 0b' + FLOAT16_ABS_MASK.toString( 2 ) ); -// => 'Binary: 0b111111111111111' +out = fromWord( out ); +console.log( 'Absolute value: %d', out ); diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js b/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js index 4576f61663eb..c395ae8a3483 100644 --- a/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js @@ -22,7 +22,7 @@ * Mask for excluding the sign bit of a half-precision floating-point number. * * @module @stdlib/constants/float16/abs-mask -* @type {number} +* @type {uinteger16} * * @example * var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' ); @@ -44,11 +44,11 @@ * ``` * * @constant -* @type {number} +* @type {uinteger16} * @default 0x7fff * @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985} */ -var FLOAT16_ABS_MASK = 0x7fff|0; +var FLOAT16_ABS_MASK = 0x7fff>>>0; // EXPORTS // diff --git a/lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js b/lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js index 63c95305010b..e3917552433a 100644 --- a/lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js +++ b/lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js @@ -21,6 +21,8 @@ // 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_ABS_MASK = require( './../lib' ); @@ -33,11 +35,24 @@ tape( 'main export is a number', function test( t ) { }); tape( 'the exported value equals 32767', function test( t ) { - t.strictEqual( FLOAT16_ABS_MASK, 32767, 'equals 32767' ); + t.strictEqual( FLOAT16_ABS_MASK, 32767, 'returns expected value' ); + t.strictEqual( FLOAT16_ABS_MASK, 0x7fff, 'returns expected value' ); t.end(); }); -tape( 'the exported value equals 0x7fff', function test( t ) { - t.strictEqual( FLOAT16_ABS_MASK, 0x7fff, 'equals 0x7fff' ); +tape( 'the exported value can be used to mask off the sign bit', function test( t ) { + var expected; + var actual; + var hi; + var x; + + x = -1.0; + hi = toWord( x ); // 1 01111 0000000000 + + actual = hi & FLOAT16_ABS_MASK; + expected = '0011110000000000'; + + t.strictEqual( toBinaryString( actual ), expected ); + t.end(); });