README.md (2743B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2021 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # toInt64Bytes 22 23 > Convert an integer-valued [double-precision floating-point number][ieee754] to a signed 64-bit integer byte array according to host byte order (endianness). 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var float64ToInt64Bytes = require( '@stdlib/number/float64/base/to-int64-bytes' ); 31 ``` 32 33 #### float64ToInt64Bytes( x ) 34 35 Converts an integer-valued [double-precision floating-point number][ieee754] to a signed 64-bit integer byte array according to host byte order (endianness). 36 37 ```javascript 38 var out = float64ToInt64Bytes( 4294967297.0 ); 39 // returns <Uint8Array> 40 ``` 41 42 #### float64ToInt64Bytes.assign( x, out, stride, offset ) 43 44 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. 45 46 ```javascript 47 var Uint8Array = require( '@stdlib/array/uint8' ); 48 49 var out = new Uint8Array( 16 ); 50 var y = float64ToInt64Bytes.assign( 4294967297.0, out, 2, 1 ); 51 // returns <Uint8Array> 52 53 var bool = ( y === out ); 54 // returns true 55 ``` 56 57 </section> 58 59 <!-- /.usage --> 60 61 <section class="notes"> 62 63 ## Notes 64 65 - The functions assume that the input value is less than the maximum safe [double-precision floating-point][ieee754] integer plus one (i.e., `2**53`). 66 67 </section> 68 69 <!-- /.notes --> 70 71 <section class="examples"> 72 73 ## Examples 74 75 <!-- eslint no-undef: "error" --> 76 77 ```javascript 78 var toBinaryStringUint8 = require( '@stdlib/number/uint8/base/to-binary-string' ); 79 var float64ToInt64Bytes = require( '@stdlib/number/float64/base/to-int64-bytes' ); 80 81 var bytes; 82 var str; 83 var sgn; 84 var x; 85 var i; 86 var j; 87 88 str = [ '', '', '', '', '', '', '', '', '' ]; 89 x = 1; 90 91 for ( i = 0; i < 54; i++ ) { 92 sgn = ( i&1 ) ? -1 : 1; 93 bytes = float64ToInt64Bytes( x*sgn ); 94 for ( j = 0; j < bytes.length; j++ ) { 95 str[ j ] = toBinaryStringUint8( bytes[ j ] ); 96 } 97 console.log( '%s2**%d => %s', ( sgn < 0 ) ? '-' : '+', i, str.join( ' ' ) ); 98 x *= 2; 99 } 100 ``` 101 102 </section> 103 104 <!-- /.examples --> 105 106 <section class="links"> 107 108 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 109 110 </section> 111 112 <!-- /.links -->