Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can someone explain why sqrt(x+1) - sqrt(x) is “inaccurate” for all x>1? Inaccurate how, and why, and why is 1/(…) any better? Thanks.


Close floating-point subtraction loses precision: when x >> 1, sqrt(x+1) ≈ sqrt(x), so their difference suffers cancellation and end up rounding to zero. In contrast, sqrt(x+1) + sqrt(x) approaches 2*sqrt(x) smoothly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: