Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
var UINT16_POSITIVE_ZERO = 0x0000; // 0x0000 = 0 => 0 00000 0000000000
var UINT16_NEGATIVE_ZERO = 0x8000; // 0x8000 = 32768 => 1 00000 0000000000
var FLOAT32_IMPLICIT_BIT = 0x800000; // 0x800000 = 8388608 => 0 00000001 00000000000000000000000
var FLOAT32_SUBNORMAL_STICKY_MASK = 0x1FFF; // 0x1FFF = 8191 => 0 00000000 00000000001111111111111

Check warning on line 41 in lib/node_modules/@stdlib/number/float16/base/to-word/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Identifier name 'FLOAT32_SUBNORMAL_STICKY_MASK' is too long (> 25)
var FLOAT32_STICKY_MASK = 0xFFF; // 0xFFF = 4095 => 0 00000000 00000000000111111111111
var MAX_MANTISSA = 0x3FF; // 0x3FF = 1023 => 0 00000 1111111111

Expand Down Expand Up @@ -123,7 +123,7 @@
mantissa = ( FLOAT32_IMPLICIT_BIT | mant ) >>> 13;

// Determine the round bit and sticky bits based on the shift amount to apply correct rounding...
if ( shift < 11 ) {
if ( shift <= 11 ) {
// Extract the round bit at the position that will be truncated after the shift:
roundBit = ( mantissa >>> ( shift - 1 ) ) & 1;

Expand Down
21 changes: 21 additions & 0 deletions lib/node_modules/@stdlib/number/float16/base/to-word/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var pow = require( '@stdlib/math/base/special/pow' );
var NINF = require( '@stdlib/constants/float16/ninf' );
var PINF = require( '@stdlib/constants/float16/pinf' );
var repeat = require( '@stdlib/string/repeat' );
Expand Down Expand Up @@ -326,3 +327,23 @@ tape( 'if provided subnormal negative values, the function returns unsigned 16-b
}
t.end();
});

tape( 'if provided subnormal values which round at the 11-bit shift boundary, the function returns correctly rounded integers', function test( t ) {
var expected;
var values;
var i;

values = [
2.98038125038147e-8, // just above 2^-25
-2.98038125038147e-8, // just below -2^-25
4.470348358154297e-8, // just below 2^-24
-4.470348358154297e-8, // just above -2^-24
pow( 2.0, -25 ), // exact tie; rounds to even (zero)
-pow( 2.0, -25 ) // exact negative tie; rounds to even (negative zero)
];
expected = [ 1, 32769, 1, 32769, 0, 32768 ];
for ( i = 0; i < values.length; i++ ) {
t.strictEqual( toWord( values[ i ] ), expected[ i ], 'x: '+values[i]+', expected: '+expected[i] );
}
t.end();
});
Loading