Number.EPSILON

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Number/EPSILON
  • Revision title: Number.EPSILON
  • Revision id: 480537
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{SeeCompatTable}}

Summary

The Number.EPSILON property represents the smallest interval between two distinguable values represented as a {{jsxref("Global_Objects/Number", "Number")}}.

Property of {{jsxref("Global_Objects/Number", "Number")}}
Writable Not writable
Enumerable Not enumerable
Configurable Not configurable

Description

The EPSILON property has a value of approximately 2.220460492503130808472633361816E-16. Values that differs by less than this cannot be distinguished when represented as a {{jsxref("Global_Objects/Number", "Number")}}.

Because EPSILON is a static property of Number, you always use it as Number.EPSILON, rather than as a property of a Number object you created.

Examples

Testing equality

x = 0.2;
y = 0.3;
equal = (Math.abs(x - y) < Math.EPSILON)

Specifications

Specification Status Comment
{{SpecName('ES6', '#sec-15.7.3.7', 'Number.EPSILON')}} {{Spec2('ES6')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatNo}} {{CompatGeckoDesktop("25.0")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatGeckoMobile("25.0")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also

  • The {{jsxref("Global_Objects/Number", "Number")}} object it belongs to.

Revision Source

<p name="Summary">{{SeeCompatTable}}</p>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <strong><code>Number.EPSILON</code></strong> property represents the smallest interval between two distinguable values represented as a {{jsxref("Global_Objects/Number", "Number")}}.</p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2">Property of<code> </code>{{jsxref("Global_Objects/Number", "Number")}}</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Writable</td>
      <td>Not writable</td>
    </tr>
    <tr>
      <td>Enumerable</td>
      <td>Not enumerable</td>
    </tr>
    <tr>
      <td>Configurable</td>
      <td>Not configurable</td>
    </tr>
  </tbody>
</table>
<h2 id="Description" name="Description">Description</h2>
<p>The <code>EPSILON</code> property has a value of approximately <code>2.220460492503130808472633361816E-16</code>. Values that differs by less than this cannot be distinguished when represented as a<code> </code>{{jsxref("Global_Objects/Number", "Number")}}.</p>
<p>Because <code><code>EPSILON</code></code> is a static property of <code>Number</code>, you always use it as <code>Number.<code>EPSILON</code></code>, rather than as a property of a <code>Number</code> object you created.</p>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Testing_equality">Testing equality</h3>
<pre class="brush: js">
<code><span class="pln">x </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0.2</span><span class="pun">;</span><span class="pln">
y </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0.3</span><span class="pun">;</span><span class="pln">
equal </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="typ">Math</span><span class="pun">.</span><span class="pln">abs</span><span class="pun">(</span><span class="pln">x </span><span class="pun">-</span><span class="pln"> y</span><span class="pun">)</span><span class="pln"> </span><span class="pun">&lt;</span><span class="pln"> Math.EPSILON</span><span class="pun">)</span></code></pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
    <tr>
      <td>{{SpecName('ES6', '#sec-15.7.3.7', 'Number.EPSILON')}}</td>
      <td>{{Spec2('ES6')}}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
  {{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatGeckoDesktop("25.0")}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatGeckoMobile("25.0")}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li>The {{jsxref("Global_Objects/Number", "Number")}} object it belongs to.</li>
</ul>
Revert to this revision