@stdlib/number-float64-base-to-int64-bytes
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.5 • Public • Published

    toInt64Bytes

    NPM version Build Status Coverage Status dependencies

    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-2021. The Stdlib Authors.

    Install

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

    Homepage

    stdlib.io

    DownloadsWeekly Downloads

    137

    Version

    0.0.5

    License

    Apache-2.0

    Unpacked Size

    46.7 kB

    Total Files

    10

    Last publish

    Collaborators

    • stdlib-bot
    • kgryte
    • planeshifter
    • rreusser