# Knowledge Base

 Navigation: Scripting Language > Operators almostequal

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.

 Supported Product: FDTD, MODE, DEVICE, INTERCONNECT

 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.

Examples

This example shows the usage of the almostequal function.

A=[1,2];

B=[1,1];

?almostequal(A,B);

result:

1 0

?almostequal(A,B,0.01,2);

result:

1 1

?almostequal(1,2,1);

result:

1