i have a function f(x)=$\sqrt{x+1/x}$ - $\sqrt{x-1/x}$ (x $\ge{1}$) and want to calculate $f(2.0004 * 10^{18})$ in floating point arithmetic with a mantissa t = 4.
First, I rounded the input to 2 * $10^{18}$ (since the 4 at the end would require a mantissa of at least 5).
Second, calculating 1/(2*$10^{18}$) we get 5.0 * $10^{-19}$.
Adding/Subtracting this value to/from 2*10$^{18}$ inside the square root however has to be rounded to 2*10$^{18}$ since $10^{-19}$ is extremely small and would require a mantissa of at least 19 to affect the result.
This way I get an result of $\sqrt{2*10^{18}}$ - $\sqrt{2*10^{18}}$ = 0, which is not the expected result according to my notes.
Also the problem seems to be numericaly well conditioned for large input values, so I would expect only a small error in the end.
Is this problem caused by the given algorithm being "bad", e.g. is there a way to write the same function avoiding such errors (e.g. by avoiding addition which is bad conditioned in case x1 ~= -x2 or is there simply an error in my calculations.
Thank you in advance for any help and suggestions