Arithmetic in Computer Hardware
thelast19digitsofpi.github.io
thelast19digitsofpi.github.io
C++ only recently (C++20 or 23) decided to declare that signed integers had to be twos-complemente.
It’s a good example of something produced by some very smart people with deep theoretical knowledge and deep experience in both things that had worked and even more things that had seemed like a good idea at the time but had turned out to be problematic in practice.
It’s a fascinating standard. The process was like the IETF’s but deeper, which is rarely possible.
(I realize the word “deep” was used a lot in this comment, but it seems appropriate)
Z_4
0 1 2 3 4 5 6 7 8 9
0 1 2 3 0 1 2 3 0 1
0 1 -2 -1 0 1 -2 -1 0 18 + -2 = 6 as you would expect.
So a subtraction is basically the addition of a negative number and you don't need any extra hardware to keep track of that.
Floating point is just the integers wearing a funny hat. Fixed point is a different funny hat. The rationals are two integers in a trenchcoat.
[0] https://blog.acolyer.org/2020/10/02/toward-an-api-for-the-re...
however, on casual inspection, the page doesn't seem to have the book available for download; possibly it is not open access
Heh. I'm not sure if this is a joke or an intentional oversimplification, but the design space for adders is pretty large, and there are all sorts of interesting adder architectures. The author describes what's called a "ripple carry" adder, which is perhaps the conceptually simplest adder, and is very efficient in logic area but very slow.
Modern adders in your M2 Pro are (just guessing) probably a much more interesting hybrid parallel-prefix adder architecture (e.g. part Kogge-Stone, part Brent-Kung, part Carry-Select or Ripple-Carry) that sits directly on the multidimensional Pareto frontier for delay/area/power.