Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/hex/functions/tests/deps.ts>asserts.assertAlmostEquals

An ecosystem delivering practices, philosophy and portability.
Go to Latest
function asserts.assertAlmostEquals
import { asserts } from "https://deno.land/x/hex@v0.4.9/functions/tests/deps.ts";
const { assertAlmostEquals } = asserts;

Make an assertion that actual and expected are almost equal numbers through a given tolerance. It can be used to take into account IEEE-754 double-precision floating-point representation limitations. If the values are not almost equal then throw.

import { assertAlmostEquals, assertThrows } from "./asserts.ts";

assertAlmostEquals(0.1, 0.2);

// Using a custom tolerance value
assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16);
assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17));

Parameters

actual: number
expected: number
optional
tolerance = [UNSUPPORTED]
optional
msg: string