5 ms·
This looks worse than the Java units: julia> 1u"kg" == 1000u"g" # Equivalence implies unit conversion true Java: Length distan
by dunefox 7y ago
This looks worse than the Java units:
julia> 1u"kg" == 1000u"g" # Equivalence implies unit conversion
true
Java:
Length distance = 100 mph * 3 hr;
- sents 7y agoYou can do this: julia> using Unitful.DefaultSymbols julia> 50m / s 50 m s^-1
- dunefox 7y agoNice, that's much better.
- ChrisRackauckas 7y agoAnd you can manually define them: const m = u"m" 50m There's actually nothing special in the compiler for unit implementation. This is just using the fact that `2x` is valid Julia code, where now x is something that overloads a dispatch to turn the number into a number with units. By default it uses string macros to keep the namespace clear, but you can fill the namespace with whatever you want.