time-to-botec/squiggle/node_modules/@stdlib/number/float64/base/to-int64-bytes/README.md
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

2.7 KiB

toInt64Bytes

Convert an integer-valued double-precision floating-point number to a signed 64-bit integer byte array according to host byte order (endianness).

Usage

var float64ToInt64Bytes = require( '@stdlib/number/float64/base/to-int64-bytes' );

float64ToInt64Bytes( x )

Converts an integer-valued double-precision floating-point number to a signed 64-bit integer byte array according to host byte order (endianness).

var out = float64ToInt64Bytes( 4294967297.0 );
// returns <Uint8Array>

float64ToInt64Bytes.assign( x, out, stride, offset )

Converts an integer-valued double-precision floating-point number to a signed 64-bit integer byte array according to host byte order (endianness) and assigns results to a provided output array.

var Uint8Array = require( '@stdlib/array/uint8' );

var out = new Uint8Array( 16 );
var y = float64ToInt64Bytes.assign( 4294967297.0, out, 2, 1 );
// returns <Uint8Array>

var bool = ( y === out );
// returns true

Notes

Examples

var toBinaryStringUint8 = require( '@stdlib/number/uint8/base/to-binary-string' );
var float64ToInt64Bytes = require( '@stdlib/number/float64/base/to-int64-bytes' );

var bytes;
var str;
var sgn;
var x;
var i;
var j;

str = [ '', '', '', '', '', '', '', '', '' ];
x = 1;

for ( i = 0; i < 54; i++ ) {
    sgn = ( i&1 ) ? -1 : 1;
    bytes = float64ToInt64Bytes( x*sgn );
    for ( j = 0; j < bytes.length; j++ ) {
        str[ j ] = toBinaryStringUint8( bytes[ j ] );
    }
    console.log( '%s2**%d => %s', ( sgn < 0 ) ? '-' : '+', i, str.join( ' ' ) );
    x *= 2;
}