A RetroSearch Logo

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

Search Query:

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

Number.EPSILON - JavaScript | MDN

Number.EPSILON

Baseline Widely available

La propriété Number.EPSILON représente la différence entre le chiffre 1 (un) et la plus petite valeur supérieure à 1 qui peut être représentée par un nombre en JavaScript.

Il n'est pas nécessaire de créer un objet Number pour accéder à cette propriété statique, elle est accessible avec Number.EPSILON.

Exemple interactif
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
Écrivable Non Énumérable Non Configurable Non Description

La propriété EPSILON vaut environ 2.2204460492503130808472633361816E-16 (ce qui correspond à 2^-52).

Exemple Tester une égalité mathématique avec un seuil de précision
x = 0.2;
y = 0.3;
equal = Math.abs(x - y) < Number.EPSILON;
Prothèse d'émulation (polyfill)
if (Number.EPSILON === undefined) {
  Number.EPSILON = Math.pow(2, -52);
}
Spécifications Compatibilité des navigateurs Voir aussi

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