Imagine that a – b < c (a, b, c are C# doubles). Is it guaranteed that a < b + c?
Thanks!
EDIT
Let’s say that the arithmetical overflow doesn’t occur unlike the following example:
double a = 1L << 53;
double b = 1;
double c = a;
Console.WriteLine(a - b < c); // Prints True
Console.WriteLine(a < b + c); // Prints False
Imagine that Math.Abs(a) < 1.0 && Math.Abs(b) < 1.0 && Math.Abs(c) < 1.0
No. Suppose a = c, a very large number, and b is a very small number. It’s possible that
a - bhas a representation less thana, buta + bis so close toa(and bigger) that it still ends up being most precisely representable asa.Here’s an example:
EDIT:
Here’s another example, which matches your edited question:
In other words, when we subtract a very small number from 1, we get a result less than 1. When we add the same number to 1, we just get 1 back due to the limitations of double precision.