@stdlib/number-float64-base-to-int64-bytes

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

Usage no npm install needed!

<script type="module">
  import stdlibNumberFloat64BaseToInt64Bytes from 'https://cdn.skypack.dev/@stdlib/number-float64-base-to-int64-bytes';
</script>

README

toInt64Bytes

NPM version Build Status Coverage Status

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

Installation

npm install @stdlib/number-float64-base-to-int64-bytes

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;
}

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2022. The Stdlib Authors.