Physical units in Julia

I am not sure if the ‘.val’ stuff is documented. And then:

julia> cm=1Unitful.cm
1 cm

julia> dm=1Unitful.dm
1 dm

julia> cm.val
1

julia> dm.val
1

We are deep in danger land here.

The unitful correct way to get a consistent unit factor is to use
ustrip and upreferred:

julia> ustrip(upreferred(cm))
1//100

julia> ustrip(upreferred(dm))
1//10

This is what the package developers recommend. I feel this generates too much boilerplate and puts the burden of consistency on the shoulders of very differently experienced individual users.

If people like the OP give up on unitful then I would say there is a missing link into the wider community. I am not really convinced that my package is best possible, but for a couple of projects I am involved in this will provide a consistent recipe how to handle things on a pragmatic level.

2 Likes