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

x/netzo/deps/std/assert/mod.ts>assertAlmostEquals

Full-stack Deno framework for building business web apps like internal tools, dashboards, admin panels and automated workflows.
Go to Latest
function assertAlmostEquals
import { assertAlmostEquals } from "https://deno.land/x/netzo@0.5.14/deps/std/assert/mod.ts";

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.

Examples

Example 1

import { assertAlmostEquals, assertThrows } from "https://deno.land/std@0.224.0/assert/mod.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