Math float equivalence

Lucas Goss lgoss007 at gmail.com
Wed Jul 5 08:10:53 PDT 2006


In many game libraries, they often have some type of float equivalence 
function to work around rounding differences, something like:

float equal(float f1, float f2, epsilon=1e-6)
{
   // check for equivalence between f1 and f2
   // where the difference between them is less than epsilon
}

How does D check for equivalence between floats, does it account for 
rounding errors? If not, is there a library function for this? I noticed 
"math.feqrel" (I still loathe the names of all these functions, I have 
no idea what feqrel is supposed to mean) which seems like it might work, 
but I would think it would take a lot more processing than to just check 
equivalence.

Thanks,
Lucas



More information about the Digitalmars-d mailing list