almostequal - Script command

Performs an almost-equal comparison. When using floating point numbers (rather than integers), two values that are meant to be equal may not be exactly equal due to rounding errors that are always present in floating point calculations. In such cases, the
almostequal
function can be useful.

Syntax

Description

out = almostequal(A, B);

Returns 1 if |A - B| is less than or equal to |A + B|/2*1e-15. Returns 0 otherwise.

out = almostequal(A, B, relative diff);

Returns 1 if |A - B| is less than or equal to |A + B|/2 times relative diff. Returns 0 otherwise.

out = almostequal(A, B, relative diff, absolute diff);

Returns 1 if |A - B| is less than or equal to |A + B|/2 times relative diff or if |A - B| is less than or equal to absolute diff. Returns 0 otherwise.