Is it possible in floating point to return 0.0 subtracting two different values?
41
3
Due to the floating point "approx" nature, its possible that two different sets of values return the same value. Example: #include <iostream> int main() { std::cout.precision(100); double a = 0.5; double b = 0.5; double c = 0.49999999999999994; std::cout << a + b << std::endl; // output "exact" 1.0 std::cout << a + c << std::endl; // output "exact" 1.0 } But is it also possible with subtraction? I mean: is there two sets of different values (keeping one value of them) that return 0.0 ? i.e. a - b = 0.0 and a - c = 0.0 , given some sets of a,b and a,c with b != c ??
c++ floating-point
share | improve