3 ms·
Scala's squants library is a nice implementation of units-of-measure/dimensional-analysis http://www.squants.com http://www.squants.com In particular it uses t
by chriswarbo 3y ago
Scala's squants library is a nice implementation of units-of-measure/dimensional-analysis http://www.squants.com http://www.squants.com
In particular it uses types for dimensions; whilst units are just constructors. Hence `Meters(2)` and `Microns(7)` have the same type (`Length`).
- bee_rider 3y agoWhat do you get if you add Meters(2) to Microns(7), out of curiosity?
- chriswarbo 3y agoEach of the dimensions has a "primary unit", which the constructors convert into. For Length it's Meters, so Meters(2) stores a 2, whilst Microns(7) will store a 0.000007 https://www.javadoc.io/doc/org.typelevel/squants_2.13/1.6.0/squants/space/Length$.html https://www.javadoc.io/doc/org.typelevel/squants_2.13/1.6.0/...
- EnigmaFlare 3y agoSurely that spoils some cases where you use different units to keep the values of reasonable magnitude? Sometimes, such as with electromagnetics, the exponents are so extreme they lead to numerical error. Sometimes also, people (inappropriately) use arbitrary epsilons to compare to zero and end up nuking micron-scale dimensions expressed in meters. A volume of 1 μm^3 is 1e-18m^3 which you might not want to operate on too hard.