3 ms·
It's a lot harder to do well than it looks, mostly because unit systems were invented by humans and have a lot of aggravating edge cases and oddities. For examp
by db48x 6y ago
It's a lot harder to do well than it looks, mostly because unit systems were invented by humans and have a lot of aggravating edge cases and oddities. For example, most units can be converted to another unit of the same dimensionality by mulitiplication or division (such as length in inches * 2.54 == length in millimeters), but then there's temperature where you also need to add or subtract an offset.
It's almost as if humans spent thousands of years inventing units without ever once considering how difficult they might be to implement in a computer programming language.
- Symbiote 6y agoAre there any edge cases if we just stick to SI units? Most of the world doesn't care about the thousand-year units, and the bit that does could just convert to them on output.
- db48x 6y agoTemperature, times, dates, cgs vs mks, dimensionless quantities, angles, the list goes on and on. And that’s before you get into the technical details of how you store units and conversion factors in memory, how you handle precision when mixing large and small units, how you interact with unlimited‐precision and rational numbers, how you use or avoid the type system in your programming language, how users of your unit library define their own units… Here’s a good write‐up of what they’re thinking about for future versions of C++: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1935r2.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p193.... It’s worth a read even if you don’t write in C++. And if you bake it into your language, you’d better get it all right the first time, because you probably won’t be able to fix it later.