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

Multiplicative and addititive identities #30

Merged
merged 2 commits into from
Jul 16, 2014
Merged

Conversation

tomasaschan
Copy link
Collaborator

This introduces one(x) and zero(x) for x of type SIQuantity.

The behavior is designed so that the two methods are multiplicative
and additive identities, respectively, i.e.

x * one(x) == x
x + zero(x) == x

This is intended to fix JuliaLang/julia#18 and at least help mitigating JuliaLang/LinearAlgebra.jl#128.

@mbauman
Copy link
Collaborator

mbauman commented Jul 16, 2014

Should these also be defined for the type? E.g., one(::Type{SIQuantity})?

Similarly useful may be nan.

@tomasaschan
Copy link
Collaborator Author

@mbauman

Should these also be defined for the type? E.g., one(::Type{SIQuantity})?

Probably a good idea. Looking at methods(one) shows, among other things,

one{T}(::Type{UniformScaling{T}}) at linalg/uniformscaling.jl:20
one{T}(J::UniformScaling{T}) at linalg/uniformscaling.jl:21

indicating that if these two are there, we probably have what we need. zero behaves similarly. I'll add these two shortly.

Similarly useful may be nan.

I'm not sure if it makes sense to have units on a NaN value. If a NaN value appears somewhere, something is probably broken, and preserving unit information is (or should be) irrelevant. If there's a use case, it's probably not difficult to add, though, but I think it can wait until someone needs it.

@mbauman
Copy link
Collaborator

mbauman commented Jul 16, 2014

If a NaN value appears somewhere, something is probably broken

Very good point. I temporarily defined nan for SIUnits at one point as I was debugging a problem… and it turned out to only be necessary because something was indeed broken. Probably better to leave it out until we have a definitive use-case. Thanks for doing this!

@tomasaschan
Copy link
Collaborator Author

There - now it will work with types as well.

Keno added a commit that referenced this pull request Jul 16, 2014
Multiplicative and addititive identities
@Keno Keno merged commit d43fdfe into Keno:master Jul 16, 2014
@tomasaschan tomasaschan deleted the identities branch July 16, 2014 17:43
@tomasaschan tomasaschan restored the identities branch July 16, 2014 18:23
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

Successfully merging this pull request may close these issues.

2.*3 parses as (2.)*(3) instead of (2).*(3)
3 participants