time-to-botec

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

x_is_zero.js (2314B)


      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 * ## Notice
     20 *
     21 * The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/s_pow.c}. The implementation follows the original, but has been modified for JavaScript.
     22 *
     23 * ```text
     24 * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
     25 *
     26 * Developed at SunPro, a Sun Microsystems, Inc. business.
     27 * Permission to use, copy, modify, and distribute this
     28 * software is freely granted, provided that this notice
     29 * is preserved.
     30 * ```
     31 */
     32 
     33 'use strict';
     34 
     35 // MODULES //
     36 
     37 var isOdd = require( './../../../../base/assert/is-odd' );
     38 var copysign = require( './../../../../base/special/copysign' );
     39 var NINF = require( '@stdlib/constants/float64/ninf' );
     40 var PINF = require( '@stdlib/constants/float64/pinf' );
     41 
     42 
     43 // MAIN //
     44 
     45 /**
     46 * Evaluates the exponential function when \\(|x| = 0\\).
     47 *
     48 * @private
     49 * @param {number} x - base
     50 * @param {number} y - exponent
     51 * @returns {number} function value
     52 *
     53 * @example
     54 * var v = pow( 0.0, 2 );
     55 * // returns 0.0
     56 *
     57 * @example
     58 * var v = pow( -0.0, -9 );
     59 * // returns -Infinity
     60 *
     61 * @example
     62 * var v = pow( 0.0, -9 );
     63 * // returns Infinity
     64 *
     65 * @example
     66 * var v = pow( -0.0, 9 );
     67 * // returns 0.0
     68 *
     69 * @example
     70 * var v = pow( 0.0, -Infinity  );
     71 * // returns Infinity
     72 *
     73 * @example
     74 * var v = pow( 0.0, Infinity );
     75 * // returns 0.0
     76 */
     77 function pow( x, y ) {
     78 	if ( y === NINF ) {
     79 		return PINF;
     80 	}
     81 	if ( y === PINF ) {
     82 		return 0.0;
     83 	}
     84 	if ( y > 0.0 ) {
     85 		if ( isOdd( y ) ) {
     86 			return x; // handles +-0
     87 		}
     88 		return 0.0;
     89 	}
     90 	// y < 0.0
     91 	if ( isOdd( y ) ) {
     92 		return copysign( PINF, x ); // handles +-0
     93 	}
     94 	return PINF;
     95 }
     96 
     97 
     98 // EXPORTS //
     99 
    100 module.exports = pow;