Exercise 2: Why the Halving Loop Is Guaranteed to Terminate — Possible Solution ==================================================================== WHY IT CAN'T LOOP FOREVER ------------------------------ The loop halves eps on every iteration: eps, eps/2, eps/4, eps/8, and so on. This chapter established (Chapter 2) that a double-precision float has only 52 mantissa bits, which means there is a hard, fixed limit on how many distinct values exist near 1.0 - specifically, values differing from 1.0 by less than roughly 2^-53 are simply indistinguishable from 1.0 when added to it, because the addition's true result can't be represented with the bits available and gets rounded back down to 1.0 itself. Each halving of eps moves it one bit-position further down. Because eps starts at a fixed, finite value (1.0) and is repeatedly divided by 2, after at most 53 halvings it necessarily crosses below the threshold where 1.0 + eps can still be distinguished from 1.0 - at that point, 1.0 + eps == 1.0 becomes true, the while condition becomes false, and the loop exits. This isn't a probabilistic or approximate argument - it follows directly and inevitably from the finite number of mantissa bits available, the same fact this chapter verified experimentally (the loop actually took exactly 53 halvings). WHY THIS ISN'T "IT JUST HAPPENS TO STOP" ------------------------------ The termination is guaranteed, not accidental, because floating-point numbers form a finite set of representable values at any given magnitude - there is no way to keep halving eps forever and always land on a new, distinguishable value, because the representable values near 1.0 are spaced no closer together than machine epsilon itself. Once eps drops below that spacing, addition simply can't tell the difference anymore, by construction of the format itself. WHY THIS WORKS AS AN ANSWER ------------------------------ The explanation grounds the termination guarantee in a specific, already-established fact (the finite 52-bit mantissa from Chapter 2) rather than describing it as an empirical accident, and connects it directly to this chapter's own verified result that the loop takes exactly 53 halvings - showing the theoretical guarantee and the observed behavior are the same underlying fact viewed two ways.