Paul wrote/converted a function for comparing singles in vba in cadvault (the address no longer works but this is close to what he wrote). Since the c languages have larger integers than vba I could never get this to work for doubles and am not too sure it works for singles all the time so I don't use it. The reading is a great article and I suspect someone with a bit of math could come up with a usable function.
'Reading http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
'Paul Marshall http://www.cadvault.com/forums/showthread.php?t=15869&page=4&pp=10
Public Function IsEqual(ByVal A As Single, ByVal B As Single, maxUlps As Long) As Boolean
' Make sure maxUlps is non-negative and small enough that the
' default NAN won't compare as equal to anything.
'maxUlps = 5 'I use this
If Not (maxUlps > 0 And maxUlps < 4& * 1024 * 1024) Then
Debug.Print "maxUlps out of range"
Stop
End If
Dim aInt As Long 'originally integer
CopyMemory aInt, A, 4
' Make aInt lexicographically ordered as a twos-complement int
If aInt < 0 Then
aInt = &H80000000 - aInt
End If
' Make bInt lexicographically ordered as a twos-complement int
Dim bInt As Long 'originally integer
CopyMemory bInt, B, 4
If bInt < 0 Then
bInt = &H80000000 - bInt
End If
' We need the range of an unsigned Long but
' there are no unsigned types available in VB
' (other than Byte).
Dim intDiff As Currency
intDiff = Abs(CCur(aInt) - bInt)
Debug.Print A, "Long " & aInt, bInt, intDiff
If intDiff <= maxUlps Then
IsEqual = True
Else
IsEqual = False
End If
End Function
'Forgot this
Public Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(dest As Any, source As Any, ByVal Length As Long)
What I use now works fine but I'm just fishing for better.
Function Rd(Num1 As Variant, Num2 As Variant) As Boolean
Dim dRet As Double
dRet = Num1 - Num2
If Abs(dRet) < 0.00000001 Then Rd = True
End Function