Using fuzz with EQUAL function, returns appear inconsistent.

Using fuzz with EQUAL function, returns appear inconsistent.

Anonymous
Not applicable
657 Views
2 Replies
Message 1 of 3

Using fuzz with EQUAL function, returns appear inconsistent.

Anonymous
Not applicable

Hi everybody,

 

I've been teaching myself AutoLISP over the past couple weeks and I have been trying to figure out the EQUAL function.

 

The book I have says that when comparing lists of two or more real numbers, the difference must be less than fuzz. But after doing some testing, that doesn't appear to be correct. It's a pretty old book so it might not still be correct. Here's what I tested:

 

When I compare the list (0.0 0.001) to (0.0 0.000) with fuzz of 0.001, it returns nil.

But comparing (0.0 15.001) to (0.0 15.000) with fuzz of 0.001 returns T.


In both sets of compared lists, the second items are .001 difference, yet one returns nil and the other returns T.

 

I was hoping someone could clarify the specific workings of the equal function that would cause these results.

 

Thanks,

Chris

 

0 Likes
658 Views
2 Replies
Replies (2)
Message 2 of 3

martti.halminen
Collaborator
Collaborator

 

This is somewhat odd, works even in a minimalist case:

 

$ (equal 0.001 0.0 0.001)
nil

 

The best guess I can give is that the fuzz factor is read using a different precision than the other parameters.

 

But anyway, your test is a little counterproductive: the fuzz exists to work with floating point inaccuracy, so trying to get an exact edge case is using it opposite its intended effect.

 

Generally, what is going on is inherent problems of the floating point representation. 

If you really want to know the details, read http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

 

- or, if you are not a computer scientist, http://floating-point-gui.de/  is probably more comprehensible. (I've never gotten further than three pages into the Goldberg article...)

 

-- 

Message 3 of 3

Anonymous
Not applicable

I figured it might have something to do with rounding but wasn't sure. I probably wouldn't use the function like that in an actual program, I was just testing to see how it works because the book I have isn't always very clear. Usually testing clears up anything the book didn't cover, but the first couple values I tried gave me those results and I was more confused than when I started.  Thanks for the links to those articles. I'll try to get through that Goldberg one when I have some spare time.

 

0 Likes