A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON below:

Number.EPSILON - JavaScript | MDN

Number.EPSILON

Baseline Widely available

A propriedade Number.EPSILON representa a diferença entre 1 e o menor ponto flutuante maior que 1.

Você não tem que criar um objeto Number para acessar esta propriedade estática (use Number.EPSILON).

Experimente
const result = Math.abs(0.2 - 0.3 + 0.1);

console.log(result);
// Expected output: 2.7755575615628914e-17

console.log(result < Number.EPSILON);
// Expected output: true
Writable no Enumerable no Configurable no Descrição

A propriedade EPSILON tem o valor de aproximadamente 2.2204460492503130808472633361816E-16, ou 2-52.

Polyfill
if (Number.EPSILON === undefined) {
  Number.EPSILON = Math.pow(2, -52);
}
Exemplos Testando igualdade
x = 0.2;
y = 0.3;
z = 0.1;
equal = Math.abs(x - y + z) < Number.EPSILON;
Especificações Compatibilidade com navegadores Veja também

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4