polyfill_Number.js.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: polyfill/Number.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: polyfill/Number.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>// Licensed Materials - Property of IBM
  20. //
  21. // IBM Watson Analytics
  22. //
  23. // (C) Copyright IBM Corp. 2015
  24. //
  25. // US Government Users Restricted Rights - Use, duplication or
  26. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  27. ( function( Number, ObjectPolyfill )
  28. {
  29. "use strict";
  30. /**
  31. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number Number}.
  32. * @class module:barejs/polyfill.Number
  33. */
  34. /** @lends module:barejs/polyfill.Number */
  35. var stat = {};
  36. /*istanbul ignore else: We test with __ES__ set to 3*/
  37. if ( __ES__ &lt; 6 )
  38. {
  39. stat.parseInt = parseInt; // ES6 defines this global should be on Number
  40. stat.parseFloat = parseFloat; // ES6 defines this global should be on Number
  41. /**
  42. * The Number.MAX_SAFE_INTEGER constant represents the maximum safe integer in JavaScript (2&lt;sup>53&lt;/sup> - 1).
  43. * @member {number}
  44. * @readonly
  45. */
  46. stat.MAX_SAFE_INTEGER = 9007199254740991 /*0x1fffffffffffff*/;
  47. /**
  48. * The Number.MIN_SAFE_INTEGER constant represents the minimum safe integer in JavaScript (-(2&lt;sup>53&lt;/sup> - 1)).
  49. * @member {number}
  50. * @readonly
  51. */
  52. stat.MIN_SAFE_INTEGER = -stat.MAX_SAFE_INTEGER;
  53. /**
  54. * The Number.EPSILON property represents the difference between `1` and the smallest floating point number greater than `1`.
  55. * @member {number}
  56. * @readonly
  57. */
  58. stat.EPSILON = Math.pow( 2, -52 );
  59. // Closure to protect the isFinite name
  60. ( function( _isFinite )
  61. {
  62. /**
  63. * Check if a number is finite. Differs from global isFinite by not coercing types.
  64. * @param _value the value to check.
  65. * @returns {boolean} True if _value is a finite number
  66. */
  67. stat.isFinite = function isFinite( _value )
  68. {
  69. return typeof _value === "number" &amp;&amp; _isFinite( _value );
  70. };
  71. }( isFinite /* Grab the global isFinite */ ) );
  72. /**
  73. * The Number.isInteger() method determines whether the passed value is an integer.
  74. * @param _value the value to check.
  75. * @returns {boolean} True if _value is an integer.
  76. */
  77. stat.isInteger = function isInteger( _value )
  78. {
  79. return Number.isFinite( _value ) &amp;&amp; Math.floor( _value ) === _value;
  80. };
  81. /**
  82. * The Number.isSafeInteger() method determines whether the provided value is a number that is a safe integer.
  83. * A safe integer is an integer that
  84. * - can be exactly represented as an IEEE-754 double precision number, and
  85. * - whose IEEE-754 representation cannot be the result of rounding any other integer to fit the IEEE-754 representation.
  86. * For example, 2&lt;sup>53&lt;/sup> - 1 is a safe integer: it can be exactly represented, and no other integer rounds to it under any IEEE-754 rounding mode.
  87. * In contrast, 2&lt;sup>53&lt;/sup> is not a safe integer: it can be exactly represented in IEEE-754, but the integer 2&lt;sup>53&lt;/sup> + 1 can't be directly represented in IEEE-754
  88. * but instead rounds to 2&lt;sup>53&lt;/sup> under round-to-nearest and round-to-zero rounding.
  89. * The safe integers consist of all integers from -(2&lt;sup>53&lt;/sup> - 1) inclusive to 2&lt;sup>53&lt;/sup> - 1 inclusive.
  90. * @param {number} _value The value to test
  91. * @returns {boolean} True if _value is a Number and a safe integer value.
  92. */
  93. stat.isSafeInteger = function isSafeInteger( _value )
  94. {
  95. return Number.isInteger( _value ) &amp;&amp; ( _value >= Number.MIN_SAFE_INTEGER ) &amp;&amp; ( _value &lt;= Number.MAX_SAFE_INTEGER );
  96. };
  97. // Closure to protect the isNaN name
  98. ( function( _isNaN )
  99. {
  100. /**
  101. * Check if _value is the special NaN value. Differs from global isNaN by not coercing types.
  102. * @param _value the value to check.
  103. * @returns {boolean} True if _value is the NaN value number
  104. */
  105. stat.isNaN = function isNaN( _value )
  106. {
  107. return typeof _value === "number" &amp;&amp; _isNaN( _value );
  108. };
  109. }( isNaN /* Grab the global isNaN */ ) );
  110. // End of ES6 polyfill scope
  111. }
  112. ObjectPolyfill.polyfill( Number, stat, null, exports, "Number" );
  113. // End of module
  114. }( Number, require( "./Object" ) ) );
  115. </code></pre>
  116. </article>
  117. </section>
  118. </div>
  119. <nav>
  120. <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>
  121. </nav>
  122. <br class="clear">
  123. <footer>
  124. 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)
  125. </footer>
  126. <script> prettyPrint(); </script>
  127. <script src="scripts/linenumber.js"> </script>
  128. </body>
  129. </html>