3 ms·
Python has operator-overloading, so you could imagine encoding some dimensionality into types such that `class Percent` has `__eq__` that knows about `class Pro
by ryanianian 7y ago
Python has operator-overloading, so you could imagine encoding some dimensionality into types such that `class Percent` has `__eq__` that knows about `class Probability` and similarly carry forward division or multiplication into runtime type info. I don't know of any libraries that do this with much success.
Personally I would view such a thing as a cool demo (or a wild abuse of operators) but I could easily imagine it becoming infuriatingly difficult to analyze/debug if operations started returning outlandish units (`print(x/y) => 1 gallon/light-year`).
My favorite tool for doing informal dimensional analysis is the `units` command-line utility. It is surprisingly adept. (It's a part of BSD and built into mac)
$ units
You have: meters/s
You want: furlongs/fortnight
* 6012.8848
/ 0.00016630952