by adrianN · 10y ago · 0 comments
if (costs[j+k] - costs[j] <= mincost)
really the same as if (costs[j+k] <= mincost + costs[j])
even with floating point math?I wonder how many of those optimizations (e.g. maybe this exact one) would be done by compilers with -ffast-math.
I could prove that a - b < c is not the same as a < b + c (large a, a=c,, b the minimum value to cause a-b change --> would result in first being true, 2nd being false)
But I couldn't think of a failure case for a - b <= c not being the same as a <= b + c.
Would love it if someone could verify/prove this.
To further complicate it, the LHS of the code in question is a float evaluation, that is then upcast to a double to compare with the right (which is a double).