Exercise 3: Why Wrapping an Accumulating Angle Is a Real Accuracy Improvement — Possible Solution ==================================================================== WHY LARGE ANGLE VALUES HAVE LESS USABLE PRECISION ------------------------------ A standard double-precision float allocates a fixed number of bits (52, per Numerical Methods & Floating-Point Computation Chapter 2) to represent a number's significant digits, regardless of that number's overall magnitude - but the ABSOLUTE SIZE of the smallest representable gap between two adjacent values grows as the number itself grows larger, since the same number of significant bits has to cover a wider range. A value near 27,400 therefore has a much coarser spacing between representable values than a value near 2*pi (about 6.28) - every unit of precision is "spread thinner" at the larger magnitude. WHY THIS DIRECTLY EXPLAINS THE VERIFIED RESULT ------------------------------ This chapter's own experiment accumulated the exact same sequence of small increments two different ways: once letting the angle grow unboundedly to about 27,400 radians, and once wrapping it back into the range [0, 2*pi) after every single addition. Every individual addition in both cases introduces some small rounding error, but in the unwrapped version, that rounding error is being added to an increasingly large number with increasingly coarse precision, so each successive addition loses more absolute precision than the last. In the wrapped version, every addition is performed on a number that stays confined to a small, consistent range near 2*pi, so each addition's rounding error stays small and consistent throughout the entire 2,000,000-frame simulation, rather than growing. This directly produced the verified nearly-four-orders-of-magnitude accuracy difference (about 3.15*10^-7 relative error unwrapped vs. about 4.54*10^-11 wrapped). WHY THIS ISN'T JUST ABOUT CODE STYLE ------------------------------ It might seem like wrapping an angle is only a matter of keeping numbers "tidy" or avoiding overflow - but this chapter's own verified numbers show it has a real, measurable effect on the actual accuracy of the resulting sin() and cos() values used to render or simulate the object's orientation. A rotating object whose angle is never wrapped doesn't just have an inconveniently large angle variable - it genuinely renders or simulates less accurately over time, purely as a side effect of floating-point representation, even though the underlying rotation logic (adding a fixed increment each frame) never changed. WHY THIS WORKS AS AN ANSWER ------------------------------ The explanation connects the specific mechanism (a double's precision being relative to its own magnitude, from the prerequisite course) to this chapter's own concrete verified numbers, and explicitly argues against treating the wrapping practice as merely stylistic, since the chapter's own experiment demonstrates a real, quantifiable accuracy cost to skipping it.