Skip to content

Commit 5fb9924

Browse files
authored
feat: add constants/float16/significand-mask
PR-URL: #8744 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 8888a89 commit 5fb9924

10 files changed

Lines changed: 505 additions & 0 deletions

File tree

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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_SIGNIFICAND_MASK
22+
23+
> Mask for the significand of a [half-precision floating-point number][ieee754].
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
<!-- eslint-disable id-length -->
30+
31+
```javascript
32+
var FLOAT16_SIGNIFICAND_MASK = require( '@stdlib/constants/float16/significand-mask' );
33+
```
34+
35+
#### FLOAT16_SIGNIFICAND_MASK
36+
37+
Mask for the significand of a [half-precision floating-point number][ieee754].
38+
39+
<!-- eslint-disable id-length -->
40+
41+
```javascript
42+
// 0x03ff = 1023 => 0 00000 1111111111
43+
var bool = ( FLOAT16_SIGNIFICAND_MASK === 0x03ff );
44+
// returns true
45+
```
46+
47+
</section>
48+
49+
<!-- /.usage -->
50+
51+
<section class="notes">
52+
53+
</section>
54+
55+
<!-- /.notes -->
56+
57+
<section class="examples">
58+
59+
## Examples
60+
61+
<!-- eslint no-undef: "error" -->
62+
63+
```javascript
64+
var toWord = require( '@stdlib/number/float16/base/to-word' );
65+
var FLOAT16_SIGNIFICAND_MASK = require( '@stdlib/constants/float16/significand-mask' );
66+
67+
var x = 11.5;
68+
var w = toWord( x ); // 0 10010 0111000000
69+
// returns 18880
70+
71+
// Mask off all bits except for the significand bits:
72+
var out = w & FLOAT16_SIGNIFICAND_MASK; // 0 00000 0111000000
73+
// returns 448
74+
75+
// Mask on the significand bits and leave other bits unchanged:
76+
out = w | FLOAT16_SIGNIFICAND_MASK; // 0 10010 1111111111
77+
// returns 19455
78+
```
79+
80+
</section>
81+
82+
<!-- /.examples -->
83+
84+
<!-- C interface documentation. -->
85+
86+
* * *
87+
88+
<section class="c">
89+
90+
## C APIs
91+
92+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
93+
94+
<section class="intro">
95+
96+
</section>
97+
98+
<!-- /.intro -->
99+
100+
<!-- C usage documentation. -->
101+
102+
<section class="usage">
103+
104+
### Usage
105+
106+
```c
107+
#include "stdlib/constants/float16/significand_mask.h"
108+
```
109+
110+
#### STDLIB_CONSTANT_FLOAT16_SIGNIFICAND_MASK
111+
112+
Macro for the mask for the significand of a [half-precision floating-point number][ieee754].
113+
114+
</section>
115+
116+
<!-- /.usage -->
117+
118+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
119+
120+
<section class="notes">
121+
122+
</section>
123+
124+
<!-- /.notes -->
125+
126+
<!-- C API usage examples. -->
127+
128+
<section class="examples">
129+
130+
</section>
131+
132+
<!-- /.examples -->
133+
134+
</section>
135+
136+
<!-- /.c -->
137+
138+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
139+
140+
<section class="related">
141+
142+
</section>
143+
144+
<!-- /.related -->
145+
146+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
147+
148+
<section class="links">
149+
150+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
151+
152+
<!-- <related-links> -->
153+
154+
<!-- </related-links> -->
155+
156+
</section>
157+
158+
<!-- /.links -->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
{{alias}}
3+
Mask for the significand of a half-precision floating-point number.
4+
5+
Examples
6+
--------
7+
> {{alias}}
8+
1023
9+
> {{alias:@stdlib/number/uint16/base/to-binary-string}}( {{alias}} )
10+
'0000001111111111'
11+
12+
See Also
13+
--------
14+
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 the significand of a half-precision floating-point number.
23+
*
24+
* @example
25+
* var mask = FLOAT16_SIGNIFICAND_MASK;
26+
* // returns 1023
27+
*/
28+
declare const FLOAT16_SIGNIFICAND_MASK: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT16_SIGNIFICAND_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_SIGNIFICAND_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_SIGNIFICAND_MASK; // $ExpectType number
28+
}
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+
'use strict';
20+
21+
var toWord = require( '@stdlib/number/float16/base/to-word' );
22+
var toBinaryString = require( '@stdlib/number/uint16/base/to-binary-string' );
23+
var FLOAT16_SIGNIFICAND_MASK = require( './../lib' );
24+
25+
var x = 11.5;
26+
var w = toWord( x );
27+
console.log( 'Word: %s', toBinaryString( w ) );
28+
29+
var out = w & FLOAT16_SIGNIFICAND_MASK;
30+
console.log( 'Isolate significand bits: %s', toBinaryString( out ) );
31+
32+
out = w | FLOAT16_SIGNIFICAND_MASK;
33+
console.log( 'Turn on significand bits: %s', toBinaryString( out ) );
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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_CONSTANTS_FLOAT16_SIGNIFICAND_MASK_H
20+
#define STDLIB_CONSTANTS_FLOAT16_SIGNIFICAND_MASK_H
21+
22+
/**
23+
* Macro for the mask for the significand of a half-precision floating-point number.
24+
*/
25+
#define STDLIB_CONSTANT_FLOAT16_SIGNIFICAND_MASK 0x03ff
26+
27+
#endif // !STDLIB_CONSTANTS_FLOAT16_SIGNIFICAND_MASK_H
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 the significand of a half-precision floating-point number.
23+
*
24+
* @module @stdlib/constants/float16/significand-mask
25+
* @type {uinteger16}
26+
*
27+
* @example
28+
* var FLOAT16_SIGNIFICAND_MASK = require( '@stdlib/constants/float16/significand-mask' );
29+
* // returns 1023
30+
*/
31+
32+
33+
// MAIN //
34+
35+
/**
36+
* Mask for the significand of a half-precision floating-point number.
37+
*
38+
* ## Notes
39+
*
40+
* The mask for the significand of a half-precision floating-point number is an unsigned 16-bit integer with the value \\( 1023 \\), which corresponds to the bit sequence
41+
*
42+
* ```binarystring
43+
* 0 00000 1111111111
44+
* ```
45+
*
46+
* @constant
47+
* @type {uinteger16}
48+
* @default 0x03ff
49+
* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}
50+
*/
51+
var FLOAT16_SIGNIFICAND_MASK = 0x03ff;
52+
53+
54+
// EXPORTS //
55+
56+
module.exports = FLOAT16_SIGNIFICAND_MASK;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
"include": [
29+
"./include"
30+
],
31+
"libraries": [],
32+
"libpath": [],
33+
"dependencies": []
34+
}
35+
]
36+
}

0 commit comments

Comments
 (0)