Unitful.jl
Unitful.jl copied to clipboard
typeof(one(typeof(1u"hr")))
Why typeof(one(typeof(1u"hr"))) is Int, not Quantity{Int64, 𝐓 , Unitful.FreeUnits{(hr,), 𝐓 , nothing}}?
Because one returns the multiplicative identity, i.e., a value such that one(x) * x == x. Therefore, one(5u"hr") cannot return a value with units hr, because 1hr * 5hr is 5 hr^2, not 5 hr.
There is a function oneunit such that oneunit(5u"hr") == 1u"hr". Maybe you want that one.
Because
onereturns the multiplicative identity, i.e., a value such thatone(x) * x == x. Therefore,one(5u"hr")cannot return a value with unitshr, because1hr * 5hris5 hr^2, not5 hr.There is a function
oneunitsuch thatoneunit(5u"hr") == 1u"hr". Maybe you want that one.
Thanx! It helps.