Equals

From Xojo Documentation

Revision as of 19:11, 19 November 2009 by 10.0.1.5 (talk) (Examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Description

Tests whether two Single or Double numbers are equal to a specified tolerance.


Syntax

Result=Expression.Equals(NumValue,MaxUIps)

Part Type Description
Expression Single or Double The numeric expression that your are testing against NumValue.
MaxUlps Int32 The number of units in the last position that are used to denote the acceptable range in the test of equality. The default is 1. If you pass zero, then the test is the same as with =.
NumValue Single or Double The numeric expression that Expression is being compared to.
Result Boolean True if Expression and NumValue are equal within the tolerance specified by MaxUlps


Notes

Use Equals rather than = when you need to determine whether two floating point numbers are close enough in value to be considered "equal." This can be used to account for the imprecision of floating point division on computers, for example. It allows for a user-specified rounding error.

The MaxUlps parameter allows you to specify the allowable range of values. For example:

Dim d as Double =10000
If d.Equals(x,1) then
//take action here..
End if


The values of x which will satisfy the equality test are: 10000.000000000002, 10000.0 and 9999.999999999998.

Examples

Dim PI as Double = 3.14159265358979323846264338327950
If PI.Equals(22/7,1)
MsgBox "The comparison is True"
End if

See Also

= operator.