I’m trying to compute the difference between two square roots in JS.
function diffSqrt(x) {
return Math.sqrt(x + 1) - Math.sqrt(x);
}
console.log(deltaSqrt(1e6)); // 0.0004999998750463419
console.log(deltaSqrt(1e12)); // 5.00003807246685e-07
console.log(deltaSqrt(1e16)); // 0.0
Why does it go all the way to 0.0 for a larger x?
I just wrote the straightforward implementation subtracting two square roots. I expected something small but non-zero like 5e-11.