time-to-botec

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

main.js (1567B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var ctors = require( './ctors.js' );
     24 
     25 
     26 // VARIABLES //
     27 
     28 var bool;
     29 
     30 
     31 // FUNCTIONS //
     32 
     33 /**
     34 * Returns a boolean indicating if an environment is little endian.
     35 *
     36 * @private
     37 * @returns {boolean} boolean indicating if an environment is little endian
     38 *
     39 * @example
     40 * var bool = isLittleEndian();
     41 * // returns <boolean>
     42 */
     43 function isLittleEndian() {
     44 	var uint16view;
     45 	var uint8view;
     46 
     47 	uint16view = new ctors[ 'uint16' ]( 1 );
     48 
     49 	/*
     50 	* Set the uint16 view to a value having distinguishable lower and higher order words.
     51 	*
     52 	* 4660 => 0x1234 => 0x12 0x34 => '00010010 00110100' => (0x12,0x34) == (18,52)
     53 	*/
     54 	uint16view[ 0 ] = 0x1234;
     55 
     56 	// Create a uint8 view on top of the uint16 buffer:
     57 	uint8view = new ctors[ 'uint8' ]( uint16view.buffer );
     58 
     59 	// If little endian, the least significant byte will be first...
     60 	return ( uint8view[ 0 ] === 0x34 );
     61 }
     62 
     63 
     64 // MAIN //
     65 
     66 bool = isLittleEndian();
     67 
     68 
     69 // EXPORTS //
     70 
     71 module.exports = bool;