Linked Questions
221 questions linked to/from How do you compare float and double while accounting for precision loss?
4
votes
4
answers
3k
views
Why two float type variables have different values [duplicate]
I have two integer vectors of nearly 1000 size, and what I am going to do is to check whether the sum of the square integer for these two vectors is the same or not. So I write the following codes:
...
8
votes
1
answer
10k
views
Modern practice to compare double/float for equality in modern C++ [duplicate]
if (std::abs(double1 - double2) < std::numeric_limits<double>::epsilon())
std::cout<<"Equal";
else
std::cout<<"Not equal";
Is this code with modern C++11/...
0
votes
8
answers
341
views
Why the control goes in "else" part? [duplicate]
Possible Duplicate:
Most effective way for float and double comparison
strange output in comparison of float with float literal
int main()
{
float a = 0.8;
if (a == 0.8)
printf("x\n");
...
0
votes
5
answers
4k
views
How to set precision for double data type variables in C? [duplicate]
Possible Duplicate:
Most effective way for float and double comparison
In my program some double variables take values of the form 1.00000001. Equality check of these variables with 1 obviously ...
5
votes
5
answers
550
views
Two General CS Questions [duplicate]
When comparing two "real" numbers for equality, why should I not use the == operator, and what should I use instead?
What is the difference between coersion and casting? It is my general assumption ...
0
votes
4
answers
2k
views
Can float values add to a sum of zero? [duplicate]
Possible Duplicate:
Most effective way for float and double comparison
I have two values(floats) I am attempting to add together and average. The issue I have is that occasionally these values ...
0
votes
3
answers
784
views
C++ Floating point gotcha [duplicate]
Possible Duplicate:
Most effective way for float and double comparison
I am new to C++. I had a doubt, while reading C++.
How to decide two floating point numbers equal to each other or not ?
...
3
votes
2
answers
2k
views
Comparing two floats/doubles in c++ [duplicate]
I read that floats/doubles equality should be implemented using an interval (given by some epsilon):
bool aresame(double a, double b)
{
return (fabs(a-b) < EPSILON);
}
Is their any predefined ...
-1
votes
3
answers
394
views
How to compare float or double? [duplicate]
Is there built-in library can compare float or double
I do not think compare like a == b or a !=b makes any sense. Any suggestion?
0
votes
2
answers
1k
views
Ideal way to test for practical floating point equality in c# [duplicate]
So I've understood for a long time that floating point equality is not perfect in any programing language. But until recently after uncovering a bug at work related to this issue, I never realized ...
1
vote
2
answers
833
views
comparing float variable [duplicate]
Possible Duplicate:
Most effective way for float and double comparison
How dangerous is it to compare floating point values?
I have const float M = 0.000001; and float input;. I want to not ...
-4
votes
5
answers
784
views
Comparing Floating Point Numbers [duplicate]
Please before you think that I'm asking the same N% Question read it first and please pay Attention to it.
I'm working on a project where I have more functions which returns double and it may be ...
Michi's user avatar
- 5,327
-5
votes
6
answers
394
views
double or float comparison [duplicate]
I've seen posts like:
What is the most effective way for float and double comparison?
Compare two floats
And many other related posts.
I saw in d3js library, it uses the following comparison:
...
0
votes
1
answer
913
views
C++ - double type alternative for subtraction of decimals? [duplicate]
I'm writing a function which accepts a double data type, say variable 't', and if 't' is equal to 0.05, the function does something.
Now, my problem is that if 't' is 100-99.5, the function fails to ...
-2
votes
1
answer
149
views
How to compare floating point variables in C++? [duplicate]
This post stated that you shouldn't compare floating point variables with == because of rounding errors. What should I use then, and when?