epsilon help

Blitz3D Forums/Blitz3D Programming/epsilon help

big10p(Posted 2004) [#1]
Hi

In order to compare floating point numbers in B3D meaningfully, I believe I have to use an 'epsilon' value when making the comparisons, something like:
epsilon# = 0.0000001
If Abs(a#-b#) < epsilon

My question is: is that epsilon value the correct one to use for all situations, or does it sometimes need to be set to a bigger value?

To simply demonstrate what I want to be able to do, imagine a point in 3D space with a given X coord, and another point moving towards it along the X axis. I want to be able to find when the moving point has reached or gone beyond the stationary point.

Any help appreciated. :)


Matty(Posted 2004) [#2]
A better way would be to use a proportional error as opposed to the true error in your values:

A simple method would be:

if abs(a-b)/(the larger of the two values a or b)<epsilon then ....

Using your method let us say that we have values for a and b which are: a=10000001 and b=10000000 then the difference will only be 1, which is greater than your epsilon value. However if you use my method you could use a constant value for epsilon.


big10p(Posted 2004) [#3]
Oooh, the plot thickens. Thanks for replying, Matty ;)


Using your method let us say that we have values for a and b which are: a=10000001 and b=10000000 then the difference will only be 1, which is greater than your epsilon value.


Yes, but isn't that correct since 10000001 does not equal 10000000?

I think I see what you're saying, though: the permitted error increases proportionally with the size of the numbers involved, yes? Using your method, would I just use a constant epsilon of 0.0000001, then?

Thanks again.


Matty(Posted 2004) [#4]
Yes you would use a constant epsilon using that method, but I would recommend making it a little larger than the value you wish to use although I don't know just how accurate you wish the value to be.


big10p(Posted 2004) [#5]
Heh, I'm not sure how accurate I need it to be, either, TBH. :P

I'll do some experimenting and will use a bigger epsilon - something like 0.00001, probably. That example was just something I saw in someone elses code.

Cheers.