TAOCP Vol 2: Seminumerical Algorithms · Week 75
TAOCP 4.2.1 Single-Precision Calculations
Updated
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.
This week's steps
3 stepsRead §4.2.1 Single-Precision Calculations
Read alongside the IEEE 754 Wikipedia page so you can map Knuth's concepts to real hardware.
Start with Ex 1, Ex 3, Ex 4; log what you solve below.
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 12M25
Prove that rounding overflow cannot happen when normalizing a quotient. The stretch.
Exercise 1528▶ Recommended
Write the fractional-part routine and handle tiny and huge inputs carefully.
Exercise 16HM21
Divide complex numbers without overflow. Smith's algorithm is still used today.
Your log
Sign in to log the exercises you work: number, rating, how far you got.
Your notes
Only youSign 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 postsQuestions 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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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.