time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (2352B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 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 # imuldw
     22 
     23 > Compute the double word product of two signed 32-bit integers.
     24 
     25 <section class="intro">
     26 
     27 </section>
     28 
     29 <!-- /.intro -->
     30 
     31 <section class="usage">
     32 
     33 ## Usage
     34 
     35 ```javascript
     36 var imuldw = require( '@stdlib/math/base/special/imuldw' );
     37 ```
     38 
     39 #### imuldw( \[out,] a, b )
     40 
     41 Multiplies two signed 32-bit integers and returns an `array` of two signed 32-bit integers which represents the signed 64-bit integer product.
     42 
     43 ```javascript
     44 var v = imuldw( 1, 10 );
     45 // returns [ 0, 10 ]
     46 
     47 v = imuldw( 0x80000000|0, 0x40000000|0 ); // -(2^31) * 2^30 = -2305843009213694000 => 32-bit integer overflow
     48 // returns [ -536870912, 0 ]
     49 ```
     50 
     51 </section>
     52 
     53 <!-- /.usage -->
     54 
     55 <section class="notes">
     56 
     57 ## Notes
     58 
     59 -   When computing the product of 32-bit integer values in double-precision floating-point format (the default JavaScript numeric data type), computing the double word product is necessary in order to **avoid** exceeding the [maximum safe double-precision floating-point integer value][@stdlib/constants/float64/max-safe-integer].
     60 
     61 </section>
     62 
     63 <!-- /.notes -->
     64 
     65 <section class="examples">
     66 
     67 ## Examples
     68 
     69 <!-- eslint no-undef: "error" -->
     70 
     71 ```javascript
     72 var lpad = require( '@stdlib/string/left-pad' );
     73 var imuldw = require( '@stdlib/math/base/special/imuldw' );
     74 
     75 var i;
     76 var j;
     77 var y;
     78 
     79 for ( i = 0x7FFFFFF0; i < 0x7FFFFFFF; i++ ) {
     80     for ( j = i; j < 0x7FFFFFFF; j++) {
     81         y = imuldw( i|0, j|0 );
     82         console.log( '%d x %d = 0x%s%s', i|0, j|0, lpad( ( y[0] >>> 0 ).toString( 16 ), 8, '0'), lpad( ( y[1] >>> 0 ).toString( 16 ), 8, '0' ) );
     83     }
     84 }
     85 ```
     86 
     87 </section>
     88 
     89 <!-- /.examples -->
     90 
     91 <section class="links">
     92 
     93 [@stdlib/constants/float64/max-safe-integer]: https://www.npmjs.com/package/@stdlib/constants-float64-max-safe-integer
     94 
     95 </section>
     96 
     97 <!-- /.links -->