Weirdness

Mike Whitaker mike at altrion.org
Mon Feb 25 19:54:26 GMT 2008


On 25 Feb 2008, at 17:42, Andy Armstrong wrote:

> On 25 Feb 2008, at 16:51, Dan Rowles wrote:
>> So my question to you is, should I report this as a bug somewhere,  
>> or should I just ignore it as "floating point weirdness"?
>
>
> The latter. It's not even weirdness to be honest - just an artefact  
> of how FP works.
>
> You should also equip your tests with
>
> sub is_approx { ... }
>
> Comparing FP numbers for equality is almost always a mistake.

Wearing my 'used to do 3D solid modelling engine development for a  
living' hat, where floating-point math kind of mattered (there are  
planes up there relying on us getting it right!)...

We used three constants: RES_LINEAR, the smallest distance two points  
can be apart and count as distinct points, RES_SIZE, the maximum  
distance we generally wanted to deal with things being away from the  
origin, and RES_ANGULAR, which was the angle subtended by two points  
RES_LINEAR apart and RES_SIZE away.

We then had utility functions to say whether two points or two angles  
were 'equal' within the above context.

Of course, you do get pathological cases, like three points A, B and  
C on a line, equally spaced just under RES_LINEAR apart, so that A  
and B are 'equal', so are B and C, but A and C technically aren't.
--
Mike Whitaker - mike at altrion.org




More information about the london.pm mailing list