123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: polyfill/Math.js</title>
- <script src="scripts/prettify/prettify.js"> </script>
- <script src="scripts/prettify/lang-css.js"> </script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
- </head>
- <body>
- <div id="main">
- <h1 class="page-title">Source: polyfill/Math.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>// Licensed Materials - Property of IBM
- //
- // IBM Watson Analytics
- //
- // (C) Copyright IBM Corp. 2015
- //
- // US Government Users Restricted Rights - Use, duplication or
- // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- ( function( Math, ObjectPolyfill )
- {
- "use strict";
- // This module polyfills bitwise operations.
- /*jshint bitwise:false*/
- /**
- * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math Math}.
- * @class module:barejs/polyfill.Math
- */
- /** @lends module:barejs/polyfill.Math */
- var stat = {};
- /*istanbul ignore else: We test with __ES__ set to 3*/
- if ( __ES__ < 6 )
- {
- /**
- * The Math.cbrt() function returns the cube root of a number.
- * @param {number} _x The number to get the cube root of.
- * @returns {number} The cube root of the number
- */
- stat.cbrt = function cbrt( _x )
- {
- var y = Math.pow( Math.abs( _x ), 1/3 );
- return _x < 0 ? -y : y;
- };
- /**
- * The Math.expm1() function returns e^x - 1, where x is the argument, and e the base of the natural logarithms.
- * @param {number} _x The number.
- * @returns {number} A number representing e^x - 1, where e is Euler's number and x is the argument.
- */
- stat.expm1 = function expm1( _x )
- {
- return Math.exp( _x ) - 1;
- };
- /**
- * The Math.hypot() function returns the square root of the sum of squares of its arguments.
- * @returns {number} The square root of the sum of squares of its arguments.
- */
- stat.hypot = function hypot( _a, _b/*, ...*/ )
- {
- for ( var i = 0, len = arguments.length, y = 0, v; i < len; ++i )
- {
- v = Math.abs( arguments[i] );
- if ( v === Infinity )
- return v;
- y += v * v;
- }
- return Math.sqrt( y );
- };
- /**
- * The Math.imul() function returns the result of the C-like 32-bit multiplication of the two parameters.
- * @param {number} _a Operand A.
- * @param {number} _b Operand B.
- * @returns {number} The result of the multiplication.
- */
- stat.imul = function imul( _a, _b )
- {
- var ah = ( _a >>> 16 ) & 0xffff;
- var al = _a & 0xffff;
- var bh = ( _b >>> 16 ) & 0xffff;
- var bl = _b & 0xffff;
- // the shift by 0 fixes the sign on the high part
- // the final |0 converts the unsigned value into a signed value
- return ( ( al * bl ) + ( ( ( ah * bl + al * bh ) << 16 ) >>> 0 ) | 0 );
- };
- ( function()
- {
- var table = [
- 32, 31, 0, 16, 0, 30, 3, 0, 15, 0, 0, 0, 29, 10, 2, 0,
- 0, 0, 12, 14, 21, 0, 19, 0, 0, 28, 0, 25, 0, 9, 1, 0,
- 17, 0, 4, undefined, 0, 0, 11, 0, 13, 22, 20, 0, 26, 0, 0, 18,
- 5, 0, 0, 23, 0, 27, 0, 6, 0, 24, 7, 0, 8, 0, 0, 0];
- /**
- * The Math.clz32() function returns the number of leading zero bits in the 32-bit binary representation of a number.
- * "clz32" is short for CountLeadingZeroes32.
- * @param {number} _x
- * @returns {number}
- */
- stat.clz32 = function clz32( _x )
- {
- var v = _x >>> 0; // convert to unsigned integer
- v |= v >>> 1;
- v |= v >>> 2;
- v |= v >>> 4;
- v |= v >>> 8;
- v |= v >>> 16;
- return table[ Math.imul( v, 0x06EB14F9 ) >>> 26 ];
- };
- }() );
- /**
- * The Math.log1p() function returns the natural logarithm (base e) of 1 + a number.
- * @param {number} _x The value to get the logarithm of.
- * @returns {number} The logarithm of 1 + _x.
- */
- stat.log1p = function log1p( _x )
- {
- return Math.log( 1 + _x );
- };
- /**
- * The Math.log2() function returns the base 2 logarithm of a number.
- * @param {number} _x The value to get the base 2 logarithm of.
- * @returns {number} The base 2 logarithm of _x.
- */
- stat.log2 = function log2( _x )
- {
- return Math.log( _x ) / Math.LN2;
- };
- /**
- * The Math.log10() function returns the base 10 logarithm of a number.
- * Note that this polyfill is subject to rounding errors.
- * @param {number} _x The value to get the base 10 logarithm of.
- * @returns {number} The base 10 logarithm of _x.
- */
- stat.log10 = function log10( _x )
- {
- return Math.log( _x ) / Math.LN10;
- };
- /**
- * The Math.cosh() function returns the hyperbolic cosine of a number.
- * @param {number} _x The value to calculate the cosine of.
- * @returns {number} The hyperbolic cosine.
- */
- stat.cosh = function cosh( _x )
- {
- var y = Math.exp( _x );
- return ( y + 1 / y ) / 2;
- };
- /**
- * The Math.acosh() function returns the hyperbolic arc-cosine of a number.
- * @param {number} _x The value to calculate the arc-cosine of.
- * @returns {number} The hyperbolic arc-cosine.
- */
- stat.acosh = function acosh( _x )
- {
- return Math.log( _x + Math.sqrt( _x * _x - 1 ) );
- };
- /**
- * The Math.sinh() function returns the hyperbolic sine of a number.
- * @param {number} _x The value to calculate the sine of.
- * @returns {number} The hyperbolic sine.
- */
- stat.sinh = function sinh( _x )
- {
- var y = Math.exp( _x );
- return ( y - 1 / y ) / 2;
- };
- /**
- * The Math.asinh() function returns the hyperbolic arcsine of a number.
- * @param {number} _x The value to calculate the arcsine of.
- * @returns {number} The hyperbolic arcsine.
- */
- stat.asinh = function asinh( _x )
- {
- if ( _x === -Infinity )
- return _x;
- else
- return Math.log( _x + Math.sqrt( _x * _x + 1 ) );
- };
- /**
- * The Math.tanh() function returns the hyperbolic tangent of a number.
- * @param {number} _x The value to calculate the tangent of.
- * @returns {number} The hyperbolic tangent.
- */
- stat.tanh = function tanh( _x )
- {
- var y;
- if ( _x === Infinity )
- return 1;
- else if ( _x === -Infinity )
- return -1;
- else
- return ( ( y = Math.exp( 2 * _x ) ) - 1) / ( y + 1 );
- };
- /**
- * The Math.atanh() function returns the hyperbolic arctangent of a number.
- * @param {number} _x The value to calculate the arctangent of.
- * @returns {number} The hyperbolic arctangent.
- */
- stat.atanh = function atanh( _x )
- {
- return Math.log( ( 1 + _x ) / ( 1 - _x ) ) / 2;
- };
- /**
- * The Math.sign() function returns the sign of a number, indicating whether the number is positive, negative or zero.
- * @param {number} _x The number to check
- * @returns {number} This function has 5 kinds of return values, 1, -1, 0, -0, NaN, which represent
- * "positive number", "negative number", "positive zero", "negative zero" and NaN respectively.
- */
- stat.sign = function sign( _x )
- {
- _x = +_x; // convert to a number
- if ( _x === 0 || isNaN( _x ) )
- return _x;
- return _x > 0 ? 1 : -1;
- };
- /**
- * Unlike other three Math methods: Math.floor(), Math.ceil() and Math.round(), the way
- * Math.trunc() works is very simple and straightforward, just truncate the dot and the digits
- * behind it, no matter whether the argument is a positive number or a negative number.
- * @param {number} _x The number to truncate.
- * @returns {number} The truncated number
- */
- stat.trunc = function trunc( _x )
- {
- return _x < 0 ? Math.ceil( _x ) : Math.floor( _x );
- };
- // End of ES6 polyfill scope
- }
- ObjectPolyfill.polyfill( Math, stat, null, exports, "Math" );
- // End of module
- }( Math, require( "./Object" ) ) );
- </code></pre>
- </article>
- </section>
- </div>
- <nav>
- <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-barejs.html">barejs</a></li><li><a href="module-barejs_polyfill.html">barejs/polyfill</a></li><li><a href="module-barejs_polyfill_Intl.html">barejs/polyfill/Intl</a></li></ul><h3>Classes</h3><ul><li><a href="module-barejs.decl.html">decl</a></li><li><a href="module-barejs.decl-Enum.html">Enum</a></li><li><a href="module-barejs.decl-Interface.html">Interface</a></li><li><a href="module-barejs.decl-SpecialType.html">SpecialType</a></li><li><a href="module-barejs.Destroyable.html">Destroyable</a></li><li><a href="module-barejs.EventArgs.html">EventArgs</a></li><li><a href="module-barejs.Evented.html">Evented</a></li><li><a href="module-barejs.Evented-EventedHandle.html">EventedHandle</a></li><li><a href="module-barejs.Exception.html">Exception</a></li><li><a href="module-barejs_polyfill.Array.html">Array</a></li><li><a href="module-barejs_polyfill.Date.html">Date</a></li><li><a href="module-barejs_polyfill.EntryStore.html">EntryStore</a></li><li><a href="module-barejs_polyfill.EntryStore.Iterator.html">Iterator</a></li><li><a href="module-barejs_polyfill.Function.html">Function</a></li><li><a href="module-barejs_polyfill.Map.html">Map</a></li><li><a href="module-barejs_polyfill.Map-MapIterator.html">MapIterator</a></li><li><a href="module-barejs_polyfill.Math.html">Math</a></li><li><a href="module-barejs_polyfill.Number.html">Number</a></li><li><a href="module-barejs_polyfill.Object.html">Object</a></li><li><a href="module-barejs_polyfill.Promise.html">Promise</a></li><li><a href="module-barejs_polyfill.Set.html">Set</a></li><li><a href="module-barejs_polyfill.Set-SetIterator.html">SetIterator</a></li><li><a href="module-barejs_polyfill.String.html">String</a></li><li><a href="module-barejs_polyfill.Symbol.html">Symbol</a></li><li><a href="module-barejs_polyfill.WeakMap.html">WeakMap</a></li><li><a href="module-barejs_polyfill.WeakSet.html">WeakSet</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat.html">DateTimeFormat</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat-DateTimeFormatOptions.html">DateTimeFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat.html">NumberFormat</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat-NumberFormatOptions.html">NumberFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl-Format.html">Format</a></li></ul>
- </nav>
- <br class="clear">
- <footer>
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 03 2018 15:59:34 GMT+0200 (W. Europe Daylight Time)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|