We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
toInt64Bytes
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url]
Convert an integer-valued [double-precision floating-point number][ieee754] to a signed 64-bit integer byte array according to host byte order (endianness).
bash
npm install @stdlib/number-float64-base-to-int64-bytes
javascript
var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' );
#### float64ToInt64Bytes( x )
Converts an integer-valued [double-precision floating-point number][ieee754] to a signed 64-bit integer byte array according to host byte order (endianness).
javascript
var out = float64ToInt64Bytes( 4294967297.0 );
// returns <Uint8Array>
#### float64ToInt64Bytes.assign( x, out, stride, offset )
Converts an integer-valued [double-precision floating-point number][ieee754] to a signed 64-bit integer byte array according to host byte order (endianness) and assigns results to a provided output array.
javascript
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
2**53
).
javascript
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;
}
@stdlib/number-float64/base/to-int32
][@stdlib/number/float64/base/to-int32]: convert a double-precision floating-point number to a signed 32-bit integer.