time-to-botec

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

main.js (1720B)


      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 toWord = require( './../../../../float32/base/to-word' );
     24 
     25 
     26 // MAIN //
     27 
     28 /**
     29 * Returns a boolean indicating if the sign bit is on (true) or off (false).
     30 *
     31 * @param {number} x - single-precision floating-point number
     32 * @returns {boolean} boolean indicating if sign bit is on or off
     33 *
     34 * @example
     35 * var toFloat32 = require( '@stdlib/number/float64/base/to-float32' );
     36 * var bool = signbitf( toFloat32( 4.0 ) );
     37 * // returns false
     38 *
     39 * @example
     40 * var toFloat32 = require( '@stdlib/number/float64/base/to-float32' );
     41 * var bool = signbitf( toFloat32( -9.14e-34 ) );
     42 * // returns true
     43 *
     44 * @example
     45 * var bool = signbitf( 0.0 );
     46 * // returns false
     47 *
     48 * @example
     49 * var bool = signbitf( -0.0 );
     50 * // returns true
     51 */
     52 function signbitf( x ) {
     53 	// Convert `x` to an unsigned 32-bit integer corresponding to the value's IEEE 754 binary representation:
     54 	var w = toWord( x );
     55 
     56 	// Shift off all bits which are not the sign bit and check if the sign bit is on:
     57 	return ( w >>> 31 ) ? true : false; // eslint-disable-line no-unneeded-ternary
     58 }
     59 
     60 
     61 // EXPORTS //
     62 
     63 module.exports = signbitf;