Floating point number fractions excercise
Actually, floating point arithmetic according to the IEEE 754 standard will calculate 1-x exactly, without any rounding error, if 0.5 ≤ x ≤ 2.0. So for x close to 1, 1-x is calculated exactly, 1 / (1-x) is calculated accurately, and 1 / (1 + x) and the sum will be calculated accurately as well. 

What you are likely observing is the rounding error when 0.999999 for example is converted to a floating point number. x will not be equal to 0.999999, but a bit off. And the function itself as a function of real numbers is very sensitive to changes in the argument. That also explains why re-arranging the function can't help, because the function is sensitive to the arguments, and the arguments are not what you think.

The same applies for x close to -1, since f(x) = f(-x). 

You will actually have a problem if x is close to 0. 1 / (1-x) and 1 / (1+x) can both be calculated with a very small absolute error, the difference is calculated exactly because both have about the same size, but because the result is close to zero, the small absolute errors turn into a rather large relative error. 

When x is close to zero, 1 / (1 - x) = 1 + x + x^2 + x^3 ..., and a / (1 + x) = 1 - x + x^2 - x^3 ..., the mathematical difference is 2x + 2x^3 + 2x^5 ... ≈ 2x. 

Let u be the value of the last bit in a number 1 ≤ x &lt; 2, then IEEE arithmetic has rounding errors up to u/2. 1 / (1 - u) ≥ 1 is calculated with an error up to u/2, 1 / (1 + u) has an error up to u/4. If you pick x^2 slightly larger than u/4, then 1 / (1 - x) is rounded to 1+x, 1 / (1 + x) is rounded to 1 - x + u/4, and the difference that is calculated is 2x - u/4, instead of 2x + x^3 + 2x^5 ..., so the absolute error is > u/4, and the relative error about $(u/4)^{1/2}$.

You can fix this easily by subtracting 1 from both sides, giving $x / (1 - x) + x / (1 + x)$.