Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why one(1u"kg") no dimension? #130

Closed
liuyxpp opened this issue Apr 8, 2024 · 2 comments
Closed

Why one(1u"kg") no dimension? #130

liuyxpp opened this issue Apr 8, 2024 · 2 comments

Comments

@liuyxpp
Copy link

liuyxpp commented Apr 8, 2024

Example below:

julia> using DynamicQuantities
julia> zero(1u"kg")
0.0 kg
julia> one(1u"kg")
1.0
julia> zero(1u"kg") |> dimension
kg
julia> one(1u"kg") |> dimension
# nothing displayed

I wonder why dimensions for the results of zero and one functions are different. Is it intentional or a bug?

@MilesCranmer
Copy link
Member

MilesCranmer commented Apr 8, 2024

This is the difference between one and oneunit. See https://docs.julialang.org/en/v1/base/numbers/#Base.oneunit

If you want a quantity that is of the same type as x, or of type T, even if x is dimensionful, use oneunit instead.

The way these are defined is that one is a multiplicative identity and zero is an additive identity. This is why one does not have units.

@MilesCranmer
Copy link
Member

@liuyxpp on #136 you can find an alternative dimensions type that permits zero(::Type)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants