19 February 2014, 21:17 UTC
If you're like me, when you write software that has to store distance information in floating point, you shudder because you know you have to pick either inches or millimeters, leading most common multiples of the other as numbers that are not exactly expressible in binary floating point.
computed by colors.py, frequency range for each colorname from
wikipedia. Unlike
the original 625nm "red" constant, common lengths are binary fractions rather
than whole numbers. And of course these aren't nice integer multiples of nm
either. I wonder why no oranges make the table.
Red: the perfect unit of measurement?
If you're like me, when you write software that has to store distance information in floating point, you shudder because you know you have to pick either inches or millimeters, leading most common multiples of the other as numbers that are not exactly expressible in binary floating point.
So let me make a simple proposal: define red = 625nm, so called because light of 625nm is commonly perceived as red. Now, you can store all of the following as exact integers:
- Any binary fraction of an inch down to 1/64inch (1/64in = 635 red)
- Any 1/10 of an inch (1/10in = 4064 red)
- Any multiple of 5um (5um = 8 red)
- 1mil = 40.64 red
- 1pspt = 1/72in ~= 564.44 red
- 1/300in (common print resolution) ~= 135.46 red
Here are some other visible-light inspired fundamental distance units and the common distances they can express exactly as binary fractions:
Color name | Exact definition | Wavelength (approximate) | Exact binary fractions for multiples of |
---|---|---|---|
red | 8192/11162109375m | 733.91nm | 1/64in mil pspt dpi nm |
red | 64/89296875m | 716.71nm | 1/64in mil pspt dpi 25nm |
red | 512/744140625m | 688.04nm | 1/64in mil dpi nm |
red | 4/5953125m | 671.92nm | 1/64in .01in dpi um |
red | 32/49609375m | 645.04nm | 1/64in mil 5nm |
red | 1/1587500m | 629.92nm | 1/64in .01in 5um |
yellow | 256/446484375m | 573.37nm | 1/64in mil pspt dpi 5nm |
green | 2/3571875m | 559.93nm | 1/64in .01in pspt 5um |
green | 2048/3720703125m | 550.43nm | 1/64in mil dpi nm |
green | 16/29765625m | 537.53nm | 1/64in mil dpi 25nm |
green | 128/248046875m | 516.03nm | 1/64in mil nm |
green | 1/1984375m | 503.94nm | 1/64in .01in um |
blue | 1024/2232421875m | 458.69nm | 1/64in mil pspt dpi nm |
violet | 8/17859375m | 447.94nm | 1/64in .01in pspt dpi um |
violet | 64/148828125m | 430.03nm | 1/64in mil dpi 5nm |
violet | 1/2381250m | 419.95nm | 1/64in .01in 5um |
violet | 512/1240234375m | 412.83nm | 1/64in mil nm |
violet | 4/9921875m | 403.15nm | 1/64in mil 25nm |
Files currently attached to this page:
colors.py | 2.4kB |
All older entries
Website Copyright © 2004-2024 Jeff Epler