Step 1 — Normalize in binary. Any nonzero real in scientific binary looks like
x=±1.b1b2b3…×2Ereal.Why this step? In base 2 the leading digit of a normalized number is always 1 (it can't be 0,
or it wouldn't be the leading digit). So we get that bit for free — it is implicit (the "hidden bit").
Step 2 — Store only the fraction. Since the leading 1 is implied, we store just f=b1b2…
So the significand is
m=1.f=1+∑i=1pbi2−i.Why this step? Storing the hidden 1 would waste a bit and buy a free bit of precision: 23 stored
fraction bits behave like 24 significant bits.
Step 3 — Bias the exponent. Exponents can be negative (2−5) or positive (2+5). Instead of a
sign for the exponent, we store
E=Ereal+bias,bias=2k−1−1
where k = number of exponent bits. Why? A plain unsigned E then lets simple integer comparison sort
floats correctly, and reserves the all-0 and all-1 patterns for special meanings.
Imagine you can only write 7 digits on a tiny card, but you also get a little "shift the dot"
note. So you write 6022 and a note "move the dot 23 places right" to mean a huge number, or "move it
left" for a tiny one. The card is the mantissa, the note is the exponent, and a +/− box is the
sign. Because the card has only a few digits, some numbers like 0.1 can't fit perfectly — you get
the closest card you can write. Two special notes are saved: one says "this is so big it's basically
infinity," and one says "this isn't a real number at all" (like dividing by zero).
Dekho, computer ke paas sirf 32 ya 64 bits hote hain, lekin real numbers infinite hote hain.
Toh IEEE 754 ek smart jugaad hai: number ko binary scientific notation me likho —
(−1)s×m×2e. Yaani ek sign bit, ek exponent (kitna shift karna hai),
aur ek mantissa (significant digits). Single precision me split hota hai 1 + 8 + 23, aur
double me 1 + 11 + 52.
Sabse mazedaar trick hai hidden bit: normalized binary number ka pehla digit hamesha 1
hota hai, toh use store karne ki zaroorat hi nahi — automatic maan lete hain. Isliye 23 stored
bits actually 24 significant bits ki tarah kaam karte hain, jo lagbhag 7 decimal digits ke
barabar hai. Exponent ko bias ke saath store karte hain (single me 127 add karke), taaki
negative exponents bhi unsigned form me aa jaayen aur comparison aasaan ho.
Special values bhi yaad rakho: exponent agar all zeros ho toh number ya to zero hai ya
subnormal (bahut chhote numbers, gradual underflow ke liye). Exponent all ones ho toh
ya ±∞ (jaise 1/0) ya NaN (jaise 0/0 ya −1). Ek important baat: NaN kabhi
khud ke barabar nahi hota, isliye x != x se NaN check karte hain.
Kyun important hai? Kyunki rounding ki wajah se 0.1+0.2=0.3 ho jaata hai computer me —
0.1 binary me exactly store hi nahi hota. Numerical methods me yahi chhoti-chhoti errors
add hoke bada blunder ban sakti hain, isliye floats ko == se compare mat karo, hamesha
tolerance ke saath compare karo.