Skip to content
Merged
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 @@ -78,7 +78,8 @@ var bool = ( w === out );

## Notes

- For accurate results, the input value should be an integer in the range \[`0`, `2^53-1`].
- A 64-bit unsigned integer has a range of \[`0`, `2^64-1`].
- Passing a number argument is safe and exact for integers within \[`0`, `2^53`]. For values exceeding `2^53`, JavaScript numbers incur precision loss.

</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface NumberToWords {
/**
* Splits a number into the high and low 32-bit words of a 64-bit unsigned integer.
*
* @param value - integer value in the range [0, 2^53-1]
* @param value - integer value
* @returns high and low words as 32-bit unsigned integers
*
* @example
Expand All @@ -47,7 +47,7 @@ interface NumberToWords {
/**
* Splits a number into the high and low 32-bit words of a 64-bit unsigned integer and assigns results to a provided output array.
*
* @param value - integer value in the range [0, 2^53-1]
* @param value - integer value
* @param out - output array
* @param stride - stride length
* @param offset - starting index
Expand All @@ -71,7 +71,7 @@ interface NumberToWords {
/**
* Splits a number into the high and low 32-bit words of a 64-bit unsigned integer.
*
* @param value - integer value in the range [0, 2^53-1]
* @param value - integer value
* @returns high and low words as 32-bit unsigned integers
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var TWO_32 = 0x100000000; // 2^32
/**
* Splits a number into the high and low 32-bit words of a 64-bit unsigned integer and assigns results to a provided output array.
*
* @param {NonNegativeInteger} value - integer value in the range [0, 2^53-1]
* @param {NonNegativeInteger} value - integer value
* @param {Collection} out - output array
* @param {integer} stride - stride length
* @param {NonNegativeInteger} offset - starting index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var assign = require( './assign.js' );
/**
* Splits a number into the high and low 32-bit words of a 64-bit unsigned integer.
*
* @param {NonNegativeInteger} value - integer value in the range [0, 2^53-1]
* @param {NonNegativeInteger} value - integer value
* @returns {Array<integer>} high and low words as 32-bit unsigned integers
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var number2words = require( './../lib/assign.js' );
// VARIABLES //

var TWO_32 = 0x100000000; // 2^32
var TWO_64 = 0x10000000000000000; // 2^64


// TESTS //
Expand Down Expand Up @@ -82,7 +83,9 @@ tape( 'the function splits a number into the high and low 32-bit words of a 64-b
UINT32_MAX + 1,
9007199254740881, // Largest prime under 2^53
MAX_SAFE_INTEGER - 1,
MAX_SAFE_INTEGER
MAX_SAFE_INTEGER,
MAX_SAFE_INTEGER + 1,
TWO_64 - 2048 // Largest integer less than 2^64 exactly representable as a double
];

for ( i = 0; i < values.length; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ tape( 'the function splits a number into the high and low 32-bit words of a 64-b
t.strictEqual( w[ 0 ], 2097151, 'returns expected value' );
t.strictEqual( w[ 1 ], 4294967295, 'returns expected value' );

w = number2words( 0x10000000000000000 - 2048 );
t.strictEqual( w[ 0 ], 4294967295, 'returns expected value' );
t.strictEqual( w[ 1 ], 4294965248, 'returns expected value' );

t.end();
});
Loading