floating point number comparison
Hi,
I heard that don't directly compare two floating numbers, since their representations in computer are inaccurate. But I still have some questions.
1. Is this only applied to the results from some arithmetic computation? If I have a floating number whose value is given instead of from computation but by assignment to a number directly or from the command line argument, is it the same case? e.g.
Code:
double v = 0; // or other real values
if (v>0){
...
}else if(v == 0){
}else if(v < 0){
}
2. Also I searched on internet on this topic. It seems to me all are about comparing if two floating numbers are the same by giving some tolerance. To compare if a floating number is bigger than the other, does it need to firstly compare if they are equal within the tolerance, then "else if" one is bigger than the other? Or can I do this without comparing equality first?
3. Can anyone recommend me a function or STL function for comparing two floating point numbers (can deal with both float and double types)?
Thanks and regards!