Skip to content
New issue

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

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

Already on GitHub? # to your account

Is one of a quantity expected to return the backing type? #748

Closed
prittjam opened this issue Nov 12, 2024 · 3 comments
Closed

Is one of a quantity expected to return the backing type? #748

prittjam opened this issue Nov 12, 2024 · 3 comments

Comments

@prittjam
Copy link

using Unitful
a = 1.0u"m"
one(eltype(a))

I would expect it to return one unit, but it just returns 1.0.

@sostock
Copy link
Collaborator

sostock commented Nov 12, 2024

The current behavior is correct, since one returns the multiplicative identity element, i.e., x * one(x) == x.

@sostock sostock closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2024
@prittjam
Copy link
Author

whats the best way to get the quantity one? e.g.,

one(eltype(x))*Unitful.unit(x[1])

@sostock
Copy link
Collaborator

sostock commented Nov 12, 2024

oneunit(x) (or oneunit(eltype(x)), since it looks like you are operating on arrays)

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

No branches or pull requests

2 participants