Code
Ways of writing that hide nothing by design — bases, bits, binary formats, floats, Unicode, Morse, QR codes, Roman numerals, timestamps, coordinates, check digits — read and written both ways.
Floating Point
Shows a number as a binary float keeps it, in IEEE 754’s half, single and double formats: the sign, the biased exponent and the fraction bit by bit, the value they hold written out exactly, the format’s numbers either side of it, and the error rounding made to the decimal typed. Every digit is worked out exactly, never by the machine’s own floats.
History, how it works, how it was checked, limits
History
A binary float keeps a number as a sign, an exponent and a fraction: 1.f × 2^e, with a hidden 1 before the fraction. IEEE 754 of 1985 fixed the formats nearly every machine now uses; David Goldberg’s paper of 1991 sets out its single and double precision, their exponents’ ranges and the special values. Most decimals, 0.1 among them, have no finite binary expansion, so what is kept is the nearest number the format has.
How it works
A decimal typed is read exactly and rounded into the format chosen to the nearest number it has, a tie going to the even fraction: half (16 bits), single (32) or double (64). Or the bits are typed, in hexadecimal or as 0s and 1s, and read back. The bits are drawn under their three fields with the exponent’s bias taken off. The rows give the value held, written out to its last digit; the shortest decimal that reads back to the same bits; the format’s numbers next below and above; and the difference between the number typed and the one kept, also as a share of the step to the next number. A line shows the number between its two neighbours, with the halfway marks where rounding turns and the decimal typed where it lies. Zero, the subnormal numbers, the infinities and NaN are each said as what they are.
How it was checked
All arithmetic is exact, in whole numbers of any size, so nothing rests on the browser’s own floats. The tests hold the bits to Node’s and to Python’s struct on some four thousand decimals, among them the largest and least numbers of each format, ties, and numbers that round up to infinity; each double’s exact value and shortest decimal read back to the same bits. RFC 8949’s Appendix A gives fifteen numbers with their bytes in the three sizes: each comes out. The parameters are checked against Goldberg’s Table D-1.
The tests hold 26 checks of this tool; 4 rest on outside material:
- A standard’s own vectors RFC 8949, Appendix A: its fifteen floats of 16, 32 and 64 bits, each decimal into the bytes it prints
- Another’s computation Python’s float and struct: the bits of 2025 decimals as doubles, the format’s edges, ties and overflows among them
- Another’s computation Python’s struct and decimal: 604 singles and 604 halves, each bit pattern’s value written out exactly
- A print’s own example Goldberg’s Table D-1: single is p 24, e max +127, e min −126, 8 exponent bits of 32; double p 53, +1023, −1022, 11 of 64
Limits
IEEE 754 itself is sold and was not read: the layout rests on Goldberg’s paper, on RFC 8949 for half precision, and on agreement with two other programs. Which NaN is quiet and which signals is therefore not said; a NaN’s fraction bits are shown as they are. Rounding is to nearest, ties to even, only. The decimal formats, the 80-bit and the 128-bit formats are not shown, and no arithmetic is done on the numbers.
- David Goldberg, What Every Computer Scientist Should Know About Floating-Point Arithmetic, ACM Computing Surveys 23 (1991): Tables D-1 and D-2
- C. Bormann and P. Hoffman, RFC 8949 (2020), Appendix A (floats of 16, 32 and 64 bits as examples) and Appendix D (half precision)
- IEEE Std 754-2019, IEEE Standard for Floating-Point Arithmetic — cited, not read here: the standard is sold