Skip to content

Commit b0c2f17

Browse files
committed
feat: add @stdlib/constants/float16/abs-mask
1 parent ca51243 commit b0c2f17

8 files changed

Lines changed: 391 additions & 0 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# FLOAT16_ABS_MASK
22+
23+
> Mask for excluding the sign bit of a [half-precision floating-point number][ieee754].
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' );
31+
```
32+
33+
#### FLOAT16_ABS_MASK
34+
35+
Mask for excluding the sign bit of a [half-precision floating-point number][ieee754].
36+
37+
```javascript
38+
// 0x7fff = 32767 => 0 11111 1111111111
39+
var bool = ( FLOAT16_ABS_MASK === 0x7fff );
40+
// returns true
41+
```
42+
43+
</section>
44+
45+
<!-- /.usage -->
46+
47+
<section class="notes">
48+
49+
## Notes
50+
51+
A [half-precision floating-point number][ieee754] has the following format:
52+
53+
```text
54+
1 11111 1111111111
55+
```
56+
57+
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.
58+
59+
</section>
60+
61+
<!-- /.notes -->
62+
63+
<section class="examples">
64+
65+
## Examples
66+
67+
<!-- eslint no-undef: "error" -->
68+
69+
```javascript
70+
var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' );
71+
72+
// Example: The bitmask in binary
73+
console.log( FLOAT16_ABS_MASK.toString( 2 ) );
74+
// => '111111111111111'
75+
76+
// Example: The bitmask as a decimal
77+
console.log( FLOAT16_ABS_MASK );
78+
// => 32767
79+
80+
// Example: The bitmask in hexadecimal
81+
console.log( '0x' + FLOAT16_ABS_MASK.toString( 16 ) );
82+
// => '0x7fff'
83+
```
84+
85+
</section>
86+
87+
<!-- /.examples -->
88+
89+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
90+
91+
<section class="related">
92+
93+
* * *
94+
95+
## See Also
96+
97+
- <span class="package-name">[`@stdlib/constants/float16/exponent-mask`][@stdlib/constants/float16/exponent-mask]</span><span class="delimiter">: </span><span class="description">mask for the exponent of a half-precision floating-point number.</span>
98+
- <span class="package-name">[`@stdlib/constants/float16/sign-mask`][@stdlib/constants/float16/sign-mask]</span><span class="delimiter">: </span><span class="description">mask for the sign bit of a half-precision floating-point number.</span>
99+
- <span class="package-name">[`@stdlib/constants/float16/significand-mask`][@stdlib/constants/float16/significand-mask]</span><span class="delimiter">: </span><span class="description">mask for the significand of a half-precision floating-point number.</span>
100+
101+
</section>
102+
103+
<!-- /.related -->
104+
105+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
106+
107+
<section class="links">
108+
109+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
110+
111+
<!-- <related-links> -->
112+
113+
[@stdlib/constants/float16/exponent-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/exponent-mask
114+
115+
[@stdlib/constants/float16/sign-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/sign-mask
116+
117+
[@stdlib/constants/float16/significand-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/significand-mask
118+
119+
<!-- </related-links> -->
120+
121+
</section>
122+
123+
<!-- /.links -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
{{alias}}
3+
Mask for excluding the sign bit of a half-precision floating-point number.
4+
5+
Examples
6+
--------
7+
> {{alias}}
8+
32767
9+
10+
See Also
11+
--------
12+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Mask for excluding the sign bit of a half-precision floating-point number.
23+
*
24+
* @example
25+
* var val = FLOAT16_ABS_MASK;
26+
* // returns 32767
27+
*/
28+
declare const FLOAT16_ABS_MASK: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT16_ABS_MASK;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
import FLOAT16_ABS_MASK = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The export is a number...
25+
{
26+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
27+
FLOAT16_ABS_MASK; // $ExpectType number
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
var FLOAT16_ABS_MASK = require( './../lib' );
22+
23+
console.log( 'Decimal: ' + FLOAT16_ABS_MASK );
24+
// => Decimal: 32767
25+
26+
console.log( 'Hexadecimal: 0x' + FLOAT16_ABS_MASK.toString( 16 ) );
27+
// => Hexadecimal: 0x7fff
28+
29+
console.log( 'Binary: 0b' + FLOAT16_ABS_MASK.toString( 2 ) );
30+
// => Binary: 0b111111111111111
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
/**
22+
* Mask for excluding the sign bit of a half-precision floating-point number.
23+
*
24+
* @module @stdlib/constants/float16/abs-mask
25+
* @type {uinteger16}
26+
*
27+
* @example
28+
* var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' );
29+
* // returns 32767
30+
*/
31+
32+
33+
// MAIN //
34+
35+
/**
36+
* Mask for excluding the sign bit of a half-precision floating-point number.
37+
*
38+
* ## Notes
39+
*
40+
* 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
41+
*
42+
* ```binarystring
43+
* 0 11111 1111111111
44+
* ```
45+
*
46+
* @constant
47+
* @type {uinteger16}
48+
* @default 0x7fff
49+
* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}
50+
*/
51+
var FLOAT16_ABS_MASK = 0x7fff|0;
52+
53+
54+
// EXPORTS //
55+
56+
module.exports = FLOAT16_ABS_MASK;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@stdlib/constants/float16/abs-mask",
3+
"version": "0.0.0",
4+
"description": "Half-precision floating-point absolute value bitmask.",
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+
"directories": {
18+
"doc": "./docs",
19+
"example": "./examples",
20+
"lib": "./lib",
21+
"test": "./test"
22+
},
23+
"types": "./docs/types",
24+
"scripts": {},
25+
"homepage": "https://github.com/stdlib-js/stdlib",
26+
"repository": {
27+
"type": "git",
28+
"url": "git://github.com/stdlib-js/stdlib.git"
29+
},
30+
"bugs": {
31+
"url": "https://github.com/stdlib-js/stdlib/issues"
32+
},
33+
"dependencies": {},
34+
"devDependencies": {},
35+
"engines": {
36+
"node": ">=0.10.0",
37+
"npm": ">2.7.0"
38+
},
39+
"os": [
40+
"aix",
41+
"darwin",
42+
"freebsd",
43+
"linux",
44+
"macos",
45+
"openbsd",
46+
"sunos",
47+
"win32",
48+
"windows"
49+
],
50+
"keywords": [
51+
"stdlib",
52+
"stdmath",
53+
"constant",
54+
"const",
55+
"mathematics",
56+
"math",
57+
"mask",
58+
"abs",
59+
"absolute",
60+
"bitmask",
61+
"ieee754",
62+
"float",
63+
"floating-point",
64+
"float16"
65+
]
66+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 tape = require( 'tape' );
24+
var FLOAT16_ABS_MASK = require( './../lib' );
25+
26+
27+
// TESTS //
28+
29+
tape( 'main export is a number', function test( t ) {
30+
t.ok( true, __filename );
31+
t.strictEqual( typeof FLOAT16_ABS_MASK, 'number', 'main export is a number' );
32+
t.end();
33+
});
34+
35+
tape( 'the exported value equals 32767', function test( t ) {
36+
t.strictEqual( FLOAT16_ABS_MASK, 32767, 'equals 32767' );
37+
t.end();
38+
});
39+
40+
tape( 'the exported value equals 0x7fff', function test( t ) {
41+
t.strictEqual( FLOAT16_ABS_MASK, 0x7fff, 'equals 0x7fff' );
42+
t.end();
43+
});

0 commit comments

Comments
 (0)