WHY 2−52? With 52 fraction bits after the implicit leading 1, the least significant bit at exponent 0 has weight 2−52. That is the resolution near 1.0.
The key word is relative: error scales with the magnitude of the number, not absolutely.
What's the relative-error amplifier in a−b? → ∣a−b∣∣a∣+∣b∣.
Is float subtraction of near-equal numbers itself inaccurate? → No, it's exact; it just exposes prior error.
Why does (a+b)+c=a+(b+c)? → Each + rounds at a place that depends on the partial sum's magnitude.
Fix for the small quadratic root? → x−=c/(ax+).
What does Kahan summation track? → The low-order bits lost in each addition.
Recall Feynman: explain to a 12-year-old
Imagine your calculator can only show 4 digits. Write 12340000 and add 1 — the calculator still shows 12340000, the 1 just fell off the edge. Now if two giant numbers are almost the same, like 12340000 and 12340000, and you subtract them, the calculator says 0 — but the real answer might have been a tiny number that got eaten earlier. So big-minus-big is dangerous: the answer is small but the mistakes are big. And 1+(huge)+(−huge) can be 0 if you do it left-to-right but 1 if you cancel the huge ones first — the order of adding changes the answer!
Dekho, computer real numbers ko exactly store nahi kar sakta — har double ke paas sirf ~15-16 significant digits hote hain (machine epsilon ≈2.2×10−16). Normally itna kaafi hai, lekin do jagah dimaag kaam karna band kar deta hai. Pehla: catastrophic cancellation. Jab tum do bade aur lagbhag barabar numbers ko subtract karte ho, answer chhota nikalta hai par jo chhoti-chhoti errors pehle se chhupi thi, woh relative terms mein bahut bada ho jaati hai. Subtraction khud galat nahi karta — woh to exact hai — bas pehle se baked error ko expose kar deta hai. Amplification factor hota hai ∣a−b∣∣a∣+∣b∣, jo a≈b pe explode karta hai.
Iska fix? Formula ko rewrite karo taaki near-equal subtraction aaye hi na. Jaise quadratic formula mein chhoti root ke liye x2=c/(ax1) use karo, ya 1−cosx ki jagah 2sin2(x/2). Yaad rakho: zyada precision (float128) ya zyada terms add karna problem solve nahi karega — asli problem expression ki conditioning hai, formula badalna padega.
Doosra gotcha: associativity failure. Maths mein (a+b)+c=a+(b+c), par floats mein nahi! Kyunki har + apne aap round karta hai. Example: a=1, b=1016, c=−1016. Left-to-right karo to 1+1016 ka chhota 1 "gir" jaata hai (absorption), phir −1016 se 0 milta hai. Par agar pehle b+c=0 karo, phir +1, to answer 1 aata hai! Isliye lambi summation mein chhote numbers pehle add karo, ya Kahan summation use karo jo lost bits ko ek compensation variable mein track karta hai. Aur kabhi floats ko == se compare mat karo — tolerance (math.isclose) use karo.