Does double z=x-y guarantee that z+y==x for IEEE 754 floating point?
I have a problem that can be reduced to this problem statement: Given a series of doubles where each is in the range [0, 1e7] , modify the last element such that the sum of the numbers equals exactly a target number. The series of doubles already sums to the target number within an epsilon (1e-7), but they are not ==. The following code is working, but is it guaranteed to work for all inputs that meet the requirements described in the first sentence? public static double[] FixIt(double[] input, double targetDouble) { var result = new double[input.Length]; if (input.Length == 0) return result;