Compute the real square root (11.5 Java EPI)

#1

I was confused by this line:
double diff = (a-b) / b;
why cant I just do:
double diff = a - b;
?
The explanation in the book is “Uses normalization for a precision problem”. I’m wondering what does normalization mean, how do we implement it and why is it needed in this problem?

3 Likes

#2

When you compare two large numbers , say 1000000000 and 1000000000.1, you might be safe to say they are equal even though their difference is 0.1. On the other hand, when you compare two small numbers, say 0.000000001 and 0.100000001, even though the difference is still 0.1, you shall not say they are equal. This is what people thought for normalization in statistics.

3 Likes