Opposite signs subtract

You will learn

How a signed add turns into a subtraction when the signs differ, and what its 3 tests leave unchecked.

sadd in gft_sadd.t27 adds two numbers of the same sign with magadd. When the signs differ it subtracts the smaller size from the larger with magsub, takes the sign of the larger, and returns 0 on an exact cancellation. The browser skips all 3 tests because its runner does not know assert_eq yet; the native t27c runs all 3, all pass, none vacuous. Only a2, 1.0 plus -1.0, mixes signs, and it cancels: magsub returns 0 at once because both sizes are equal. No test subtracts two different sizes, so the sign of the larger never decides a result. The recording runs t27c test-report, then a one-line sed that adds the sizes in the branch a2 takes, and t27c test-report again: exactly one test fails, a2. git checkout puts the line back, and sha256sum prints the same hash as before the edit. Every byte in the recording was printed by the command; only the typing is staged.

Open the interactive lesson →