HI all
I need a piece of code that will compare 3 numbers of type floating point and then list them in some order eg largest num first then second largest etc. (order dont matter really).
thanx ppl
HI all
I need a piece of code that will compare 3 numbers of type floating point and then list them in some order eg largest num first then second largest etc. (order dont matter really).
thanx ppl
Comparing floats is a dodgy business as any difference no matter how small will effect your comparison, example:
Say at this point in your program you expect that num1 should be 25.5 and num2 should also be 25.5. But if num1 is actually 25.50001 then the test for comparison will fail.Code:if( num1 == num2 ) // do stuff
Last edited by C_Coder; 03-30-2002 at 03:32 AM.
All spelling mistakes, syntatical errors and stupid comments are intentional.
Why dont you define some error of size, say 1e-4. Then just see if the difference between them is less than the error.
float error = 1e-4;
if(abs(num1 - num2) < error)
{
// do stuff...
}
If you're working with floats in the first place, there is going to be round off errors anyway...