Linked Questions

4 votes
4 answers
3k views

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: ...
feelfree's user avatar
  • 11.9k
8 votes
1 answer
10k views

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/...
Bruice's user avatar
  • 713
0 votes
8 answers
341 views

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"); ...
user1593308's user avatar
0 votes
5 answers
4k views

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 ...
stressed_geek's user avatar
5 votes
5 answers
550 views

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

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 ...
Evan's user avatar
  • 279
0 votes
3 answers
784 views

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 ? ...
Jholar99's user avatar
3 votes
2 answers
2k views

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 ...
John Lui's user avatar
  • 1,484
-1 votes
3 answers
394 views

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?
Adam Lee's user avatar
  • 26k
0 votes
2 answers
1k views

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 ...
nmg49's user avatar
  • 1,406
1 vote
2 answers
833 views

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 ...
user1802858's user avatar
-4 votes
5 answers
785 views

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

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: ...
gongzhitaao's user avatar
  • 6,732
0 votes
1 answer
913 views

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 ...
user3073511's user avatar
-2 votes
1 answer
149 views

This post stated that you shouldn't compare floating point variables with == because of rounding errors. What should I use then, and when?
-2 votes
1 answer
277 views

I use relative comparison as it described here. I have two doubles. The first of them is result of computation: double d1(callComputation() ); The second is defined as following: double d2(0.009); ...
mhd's user avatar
  • 545
0 votes
1 answer
112 views

I have two floating points, x, y. They are "supposed to be" the same, but with floating-point, you never know, so x == y may return False. So I am looking for an operation O() which ensures ...
0 votes
1 answer
83 views

What can I do to compare two variables of type float accurately in C++, one being initialized at the time of declaration and the other being computed through the program? When I am comparing two ...
1 vote
0 answers
80 views

I'm trying to implement Linspace in c++ I created some random tests and have a problem with precision I don't understand why. c++ implementation std::vector<double> libcalc::linear_space(...
Gilad's user avatar
  • 6,625
0 votes
0 answers
46 views

I have the following code which minus 0.1 from 0.5 for 5 times, but the result isn't exact 0.0. I understand why there is an error, and I'm finding a way to deal with it. The only way I came up with ...
Pegasis's user avatar
  • 1,444
0 votes
0 answers
38 views

I wrote a small test to evaluate my programm, but somehow a weired thing happens: Values of the vector(as printed using 'cout' in the first loop): 0.06 0.06 0.06 0.06 0.06 0.6 ...
226 votes
12 answers
90k views

Today, I was looking through some C++ code (written by somebody else) and found this section: double someValue = ... if (someValue < std::numeric_limits<double>::epsilon() && ...
133 votes
13 answers
160k views

I'm currently writing some code where I have something along the lines of: double a = SomeCalculation1(); double b = SomeCalculation2(); if (a < b) DoSomething2(); else if (a > b) ...
63 votes
10 answers
67k views

http://msdn.microsoft.com/en-us/library/system.double.epsilon.aspx If you create a custom algorithm that determines whether two floating-point numbers can be considered equal, you must use a ...
ss2k's user avatar
  • 1,288
93 votes
9 answers
193k views

The C++ FAQ lite "[29.17] Why doesn't my floating-point comparison work?" recommends this equality test: #include <cmath> /* for std::abs(double) */ inline bool isEqual(double x, ...
106 votes
4 answers
72k views

I assume that abs and fabs are behaving different when using math.h. But when I use just cmath and std::abs, do I have to use std::fabs or fabs? Or isn't this defined?
math's user avatar
  • 8,870
66 votes
5 answers
16k views

int main() { float a = 0.7; float b = 0.5; if (a < 0.7) { if (b < 0.5) printf("2 are right"); else printf("1 is right"); } else printf("0 are right")...
sasidhar's user avatar
  • 7,822
51 votes
7 answers
13k views

I have a double value f and would like a way to nudge it very slightly larger (or smaller) to get a new value that will be as close as possible to the original but still strictly greater than (or less ...
Owen's user avatar
  • 7,874
43 votes
8 answers
78k views

Every time I start a new project and when I need to compare some float or double variables I write the code like this one: if (fabs(prev.min[i] - cur->min[i]) < 0.000001 && fabs(...
32 votes
7 answers
44k views

The following code in C# doesn't work: int iValue = 0; double dValue = 0.0; bool isEqual = iValue.Equals(dValue); So, the question: what's the best way to compare Double and Int?

15 30 50 per page
1
2 3 4 5
...
8