Unitful.jl icon indicating copy to clipboard operation
Unitful.jl copied to clipboard

typeof(one(typeof(1u"hr")))

Open PharmCat opened this issue 3 years ago • 2 comments

Why typeof(one(typeof(1u"hr"))) is Int, not Quantity{Int64, 𝐓 , Unitful.FreeUnits{(hr,), 𝐓 , nothing}}?

PharmCat avatar Sep 04 '22 14:09 PharmCat

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.

sostock avatar Sep 04 '22 15:09 sostock

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.

Thanx! It helps.

PharmCat avatar Sep 05 '22 07:09 PharmCat