you might be confusing what maxUps really is…
it does NOT compare the DIGITS in the number… it compares the BYTES in the internal representation of the number.
so it is not as straight forward as you might be thinking…
The problem is that that’s a poorly designed example. Pi and 22/7 are just too different. You would have to round to 2 or 3 decimal places to get them to be equal.
Thank you Jeff. Your code works, I just want to learn what Xojo offer. From what I read, your code and some math, I think is possible to create almost any function that we need to solve what we want.
Thank you Tim. The problem is that I don’t understand the example, so I can’t file a Feedback case. I have opened a couple (wrong documentation) and Paul fixed them quickly.
// we have 2 double values that vary by a tiny bit
Dim d1 As Double = 3.1415926535897935
Dim d2 As Double = 3.1415926535897933
if d1 = d2 then
// will not get here because they are not an exact match
end
if d1.equals(d2, 1) then
// will get here because they are "close enough"
end
I had the same experience that Alberto did at one point and finally retreated from this method which is, as S points out, not for the faint-hearted.
I think that this is a confusing topic and I think that the documentation should be updated to make this fact clearer. For one thing, the word maxUlps should be defined.
Maximum number of representable floating point that are allowed to be between the two values.
maxUlp: maximum Units in the last place
This might be enough to keep the non-experts who stumble across this method away.
The URL
might be included just to further point out this is not for amateurs. Nice discussion.