time-to-botec

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

README.md (1906B)


      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 # toInt32
     22 
     23 > Convert an unsigned 32-bit integer to a signed 32-bit integer.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var uint32ToInt32 = require( '@stdlib/number/uint32/base/to-int32' );
     31 ```
     32 
     33 #### uint32ToInt32( x )
     34 
     35 Converts an unsigned 32-bit integer to a signed 32-bit integer.
     36 
     37 ```javascript
     38 var float64ToUint32 = require( '@stdlib/number/float64/base/to-uint32' );
     39 
     40 var y = uint32ToInt32( float64ToUint32( 4294967295 ) );
     41 // returns -1
     42 
     43 y = uint32ToInt32( float64ToUint32( 3 ) );
     44 // returns 3
     45 ```
     46 
     47 </section>
     48 
     49 <!-- /.usage -->
     50 
     51 <section class="examples">
     52 
     53 ## Examples
     54 
     55 <!-- eslint no-undef: "error" -->
     56 
     57 ```javascript
     58 var randu = require( '@stdlib/random/base/randu' );
     59 var MAX_UINT32 = require( '@stdlib/constants/uint32/max' );
     60 var float64ToUint32 = require( '@stdlib/number/float64/base/to-uint32' );
     61 var uint32ToInt32 = require( '@stdlib/number/uint32/base/to-int32' );
     62 
     63 var uint32;
     64 var int32;
     65 var i;
     66 
     67 for ( i = 0; i < 100; i++ ) {
     68     // Generate a random unsigned 32-bit integer:
     69     uint32 = float64ToUint32( randu()*MAX_UINT32 );
     70 
     71     // Convert the unsigned integer to a signed 32-bit integer:
     72     int32 = uint32ToInt32( uint32 );
     73 
     74     console.log( 'uint32: %d => int32: %d', uint32, int32 );
     75 }
     76 ```
     77 
     78 </section>
     79 
     80 <!-- /.examples -->
     81 
     82 <section class="links">
     83 
     84 </section>
     85 
     86 <!-- /.links -->