TAOCP Vol 2: Seminumerical Algorithms · Week 75

TAOCP 4.2.1 Single-Precision Calculations

Updated

About 8 hours19 exercises, rated 10 to 40

Summary

TAOCP 4.2.1 Single-Precision Calculations: How floating-point numbers are stored (sign, exponent, fraction) and the algorithms for add, subtract, multiply and divide, including normalization and rounding. Budget about 8 hours; do exercises 1, 3 and 4.

Knuth uses his own floating format on MIX, not IEEE 754.

Flashcards 14 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §4.2.1 Single-Precision Calculations

    Read alongside the IEEE 754 Wikipedia page so you can map Knuth's concepts to real hardware.

  2. Work the exercises (8 picked)

    Start with Ex 1, Ex 3, Ex 4; log what you solve below.

  3. Write down one thing you'd explain to someone

    A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

Sign in to track this: tick each step off and it counts toward your week.

Exercises

This section has 19 exercises, rated 10 to 40, and Knuth marks 1 of them with the triangle for recommended. Only one exercise here is marked recommended, so choose by usefulness: work the small examples by hand, then compare what IEEE 754 does in the same cases.

Worth your time

  • Exercise 110

    Encode two physical constants in a toy floating-point format.

    Discuss

  • Exercise 311

    The hidden leading bit trick. IEEE 754 uses it.

    Discuss

  • Exercise 416

    Trace floating addition on concrete inputs, including a catastrophic one.

    Discuss

  • Exercise 1012

    Find a case where rounding pushes the fraction past 1 during addition.

    Discuss

  • Exercise 12M25

    Prove that rounding overflow cannot happen when normalizing a quotient. The stretch.

    Discuss

  • Exercise 1330

    Directed rounding for interval arithmetic.

    Discuss

  • Exercise 1528▶ Recommended

    Write the fractional-part routine and handle tiny and huge inputs carefully.

    Discuss

  • Exercise 16HM21

    Divide complex numbers without overflow. Smith's algorithm is still used today.

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about the reading go here; each exercise has its own thread below. Hints over answers.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Exercise threads

One thread per exercise. Open one to ask for a nudge or check your thinking.

  • Exercise 110No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 311No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 416No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1012No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 12M25No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1330No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1528No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 16HM21No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

Floats are in almost every program and most programmers have only a vague model of them. Implementing float addition yourself is the fastest way to understand why 0.1 + 0.2 is not 0.3.

Before you start
  • 4.1 Positional Number Systems
  • Basic MIX
How to approach it

Read alongside the IEEE 754 Wikipedia page so you can map Knuth's concepts to real hardware. Implement float addition on a toy format (say 8-bit exponent and 16-bit fraction) in C using integers.

Common traps
  • Assuming Knuth's format matches IEEE 754. The ideas transfer, the bit layouts do not.

Spot a mistake? Report it

Back to week 75