Skip to content

Commit 23244f7

Browse files
committed
chore: clean-up
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 1042c07 commit 23244f7

6 files changed

Lines changed: 46 additions & 46 deletions

File tree

lib/node_modules/@stdlib/constants/float16/abs-mask/README.md

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ var bool = ( FLOAT16_ABS_MASK === 0x7fff );
4646

4747
<section class="notes">
4848

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-
5949
</section>
6050

6151
<!-- /.notes -->
@@ -67,19 +57,22 @@ where the first bit is the sign bit, the next 5 bits are the exponent, and the l
6757
<!-- eslint no-undef: "error" -->
6858

6959
```javascript
60+
var toWord = require( '@stdlib/number/float16/base/to-word' );
61+
var fromWord = require( '@stdlib/number/float16/base/from-word' );
62+
var toBinaryString = require( '@stdlib/number/uint32/base/to-binary-string' );
7063
var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' );
7164

72-
// Example: The bitmask in binary
73-
console.log( FLOAT16_ABS_MASK.toString( 2 ) );
74-
// => '111111111111111'
65+
var x = -11.5;
66+
var w = toWord( x ); // 1 10010 0111000000
67+
// returns 51648
7568

76-
// Example: The bitmask as a decimal
77-
console.log( FLOAT16_ABS_MASK );
78-
// => 32767
69+
// Turn off the sign bit and leave other bits unchanged:
70+
var out = w & FLOAT16_ABS_MASK; // 0 10010 0111000000
71+
// returns 18880
7972

80-
// Example: The bitmask in hexadecimal
81-
console.log( '0x' + FLOAT16_ABS_MASK.toString( 16 ) );
82-
// => '0x7fff'
73+
// Generate a new value:
74+
out = fromWord( out );
75+
// returns 11.5
8376
```
8477

8578
</section>
@@ -144,14 +137,6 @@ Macro for the mask for excluding the sign bit of a [half-precision floating-poin
144137

145138
<section class="related">
146139

147-
* * *
148-
149-
## See Also
150-
151-
- <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>
152-
- <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>
153-
- <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>
154-
155140
</section>
156141

157142
<!-- /.related -->
@@ -164,12 +149,6 @@ Macro for the mask for excluding the sign bit of a [half-precision floating-poin
164149

165150
<!-- <related-links> -->
166151

167-
[@stdlib/constants/float16/exponent-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/exponent-mask
168-
169-
[@stdlib/constants/float16/sign-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/sign-mask
170-
171-
[@stdlib/constants/float16/significand-mask]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float16/significand-mask
172-
173152
<!-- </related-links> -->
174153

175154
</section>

lib/node_modules/@stdlib/constants/float16/abs-mask/docs/repl.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
--------
77
> {{alias}}
88
32767
9+
> {{alias:@stdlib/number/uint16/base/to-binary-string}}( {{alias}} )
10+
'0111111111111111'
911

1012
See Also
1113
--------

lib/node_modules/@stdlib/constants/float16/abs-mask/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Mask for excluding the sign bit of a half-precision floating-point number.
2323
*
2424
* @example
25-
* var val = FLOAT16_ABS_MASK;
25+
* var mask = FLOAT16_ABS_MASK;
2626
* // returns 32767
2727
*/
2828
declare const FLOAT16_ABS_MASK: number;

lib/node_modules/@stdlib/constants/float16/abs-mask/examples/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818

1919
'use strict';
2020

21+
var toWord = require( '@stdlib/number/float16/base/to-word' );
22+
var fromWord = require( '@stdlib/number/float16/base/from-word' );
23+
var toBinaryString = require( '@stdlib/number/uint32/base/to-binary-string' );
2124
var FLOAT16_ABS_MASK = require( './../lib' );
2225

23-
console.log( 'Decimal: ' + FLOAT16_ABS_MASK );
24-
// => 'Decimal: 32767'
26+
var x = -11.5;
27+
var w = toWord( x );
28+
console.log( 'Word: %s', toBinaryString( w ) );
2529

26-
console.log( 'Hexadecimal: 0x' + FLOAT16_ABS_MASK.toString( 16 ) );
27-
// => 'Hexadecimal: 0x7fff'
30+
var out = w & FLOAT16_ABS_MASK;
31+
console.log( 'Turn off sign bits: %s', toBinaryString( out ) );
2832

29-
console.log( 'Binary: 0b' + FLOAT16_ABS_MASK.toString( 2 ) );
30-
// => 'Binary: 0b111111111111111'
33+
out = fromWord( out );
34+
console.log( 'Absolute value: %d', out );

lib/node_modules/@stdlib/constants/float16/abs-mask/lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Mask for excluding the sign bit of a half-precision floating-point number.
2323
*
2424
* @module @stdlib/constants/float16/abs-mask
25-
* @type {number}
25+
* @type {uinteger16}
2626
*
2727
* @example
2828
* var FLOAT16_ABS_MASK = require( '@stdlib/constants/float16/abs-mask' );
@@ -44,11 +44,11 @@
4444
* ```
4545
*
4646
* @constant
47-
* @type {number}
47+
* @type {uinteger16}
4848
* @default 0x7fff
4949
* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}
5050
*/
51-
var FLOAT16_ABS_MASK = 0x7fff|0;
51+
var FLOAT16_ABS_MASK = 0x7fff>>>0;
5252

5353

5454
// EXPORTS //

lib/node_modules/@stdlib/constants/float16/abs-mask/test/test.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var toBinaryString = require( '@stdlib/number/uint16/base/to-binary-string' );
25+
var toWord = require( '@stdlib/number/float16/base/to-word' );
2426
var FLOAT16_ABS_MASK = require( './../lib' );
2527

2628

@@ -33,11 +35,24 @@ tape( 'main export is a number', function test( t ) {
3335
});
3436

3537
tape( 'the exported value equals 32767', function test( t ) {
36-
t.strictEqual( FLOAT16_ABS_MASK, 32767, 'equals 32767' );
38+
t.strictEqual( FLOAT16_ABS_MASK, 32767, 'returns expected value' );
39+
t.strictEqual( FLOAT16_ABS_MASK, 0x7fff, 'returns expected value' );
3740
t.end();
3841
});
3942

40-
tape( 'the exported value equals 0x7fff', function test( t ) {
41-
t.strictEqual( FLOAT16_ABS_MASK, 0x7fff, 'equals 0x7fff' );
43+
tape( 'the exported value can be used to mask off the sign bit', function test( t ) {
44+
var expected;
45+
var actual;
46+
var hi;
47+
var x;
48+
49+
x = -1.0;
50+
hi = toWord( x ); // 1 01111 0000000000
51+
52+
actual = hi & FLOAT16_ABS_MASK;
53+
expected = '0011110000000000';
54+
55+
t.strictEqual( toBinaryString( actual ), expected );
56+
4257
t.end();
4358
});

0 commit comments

Comments
 (0)