equalTol?()

Synopsis

Compares two numbers and returns True is they are within tolerance of each other.

Syntax

equalTol? ( num1 As Number, _
             num2 As Number, _
             Optional tolerance As Number = 0.001 ) As Boolean 
Argument Type Description
num1 number The first number to compare.
num2 number The second number to compare.
tolerance Number Optional; tolerance to use for the comparison; default is 0.001. If the numbers are different by no more than this value, then the numbers are considered equal.

Example 1

Intent >equalTol?(1.9996, 2.0004) 
--> True 
This uses the default tolerance of 0.001.

Example 2

Intent >equalTol?(1.96, 2.04) 
--> False 
This uses the default tolerance of 0.001. Since the numbers are actually 0.08 apart, the comparison fails.

Example 3

Intent >equalTol?(1.96, 2.04, tolerance := 0.1) 
--> True 
Here, a specific less-precise tolerance is specified, resulting in a match.