diff --git a/lib/node_modules/@stdlib/number/float16/base/to-word/lib/main.js b/lib/node_modules/@stdlib/number/float16/base/to-word/lib/main.js index f1190a54ff9d..d3fffaee6d66 100644 --- a/lib/node_modules/@stdlib/number/float16/base/to-word/lib/main.js +++ b/lib/node_modules/@stdlib/number/float16/base/to-word/lib/main.js @@ -123,7 +123,7 @@ function toWord( x ) { 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; diff --git a/lib/node_modules/@stdlib/number/float16/base/to-word/test/test.js b/lib/node_modules/@stdlib/number/float16/base/to-word/test/test.js index 49c8045c85dc..a5538453f414 100644 --- a/lib/node_modules/@stdlib/number/float16/base/to-word/test/test.js +++ b/lib/node_modules/@stdlib/number/float16/base/to-word/test/test.js @@ -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' ); @@ -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(); +});