Floating Point Numbers (IEEE 754)

Context: FIT1047_MOC · binary scientific notation for numbers of varying scale · significand + exponent + sign · why is inexact

Quick Revision

  • 🎯 Objective: represent with fixed-size fields ➔ IEEE 754 double: 52-bit significand + 11-bit exponent + 1 sign bit bits.
  • 📦 Core Components: binary point ➔ normalise to ➔ store fraction + exponent (excess-).
  • ⚡ Key Constraint: finite bits ⟹ rounding — has no exact binary form; errors accumulate.

📝 Core

  • Motivation ➔ integers can’t hold km/s and s in one scheme (scaling is ad-hoc; rounding gives ) ➔ scientific notation makes it easy: km.
  • Binary fractions ➔ positions right of the point weigh : .
  • Normalisation ➔ shift the point so the number starts "": — exponent = shift count.
  • Storage (IEEE 754 double) ➔ sign bit · exponent bits · significand bits; special FPU hardware computes on these.
  • Exponent encoding ➔ negative exponents needed ➔ stored in excess- (biased), not 2’s complement (detail out of W1 scope).
  • Precision trade ➔ 64-bit float vs 64-bit int: the float spends 12 bits on sign+exponent ⟹ large integers stored as floats lose exactness.
  • The problem ➔ no finite sum of powers of equals ; IEEE 754 stores — tiny per-operation errors compound ⟹ never floats for money.

📊 Applied Exercise — encode (6-bit significand, 4-bit exponent, from lecture)

Final Extracted Output: significand , exponent , sign .

✍️ Practice

⚠️ Common Mistakes

  • 💡 “Looks exact” isn’t ➔ printed hides the stored ; equality tests on floats (a == 0.3) fail unpredictably.
  • 💡 Floats don’t replace ints ➔ same 64 bits, but floats trade exactness for range; big integers silently round.
  • 💡 Exponent isn’t 2’s complement ➔ IEEE 754 uses excess- bias — don’t decode exponent fields with the signed-integer rules.