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

one and zero inconsistency #291

Closed
rohanmclure opened this issue Dec 16, 2019 · 3 comments
Closed

one and zero inconsistency #291

rohanmclure opened this issue Dec 16, 2019 · 3 comments

Comments

@rohanmclure
Copy link

It appears that calling one on quantity types outputs the one of the backing type. By contrast, zero will output the zero of the quantity, e.g:

julia> Q = typeof(1.0u"m")
Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}

julia> zero(Q)
0.0 m

julia> one(Q)
1.0

Not sure if I should be using a different method to obtain the unitary element of the type, but I believe these two methods should provide the same type.

@cstjean
Copy link
Contributor

cstjean commented Dec 16, 2019

julia> oneunit(Q)
1.0 m

help?> oneunit
search: oneunit DimensionlessQuantity

  oneunit(x::T)
  oneunit(T::Type)

  Returns T(one(x)), where T is either the type of the argument or (if a type
  is passed) the argument. This differs from one for dimensionful quantities:
  one is dimensionless (a multiplicative identity) while oneunit is
  dimensionful (of the same type as x, or of type T).

@cstjean
Copy link
Contributor

cstjean commented Dec 16, 2019

It's confusingly named. zero should be called zerounit, but it was decided in julialang that it's not worth changing IIRC.

@rohanmclure
Copy link
Author

Thanks! That makes sense.

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