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

hypot errors when both units are zero #143

Closed
platawiec opened this issue Jun 26, 2018 · 1 comment
Closed

hypot errors when both units are zero #143

platawiec opened this issue Jun 26, 2018 · 1 comment

Comments

@platawiec
Copy link

On Julia 0.6.2:

import Unitful: m

hypot(0.0m, 0.0m)

gives the error:

ERROR: DimensionError: m and NaN are not dimensionally compatible.
Stacktrace:
 [1] hypot(::Unitful.Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)},Unitful.FreeUnits{(Unitful.Unit{:Meter,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}(0, 1//1),),Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}}, ::Unitful.Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)},Unitful.FreeUnits{(Unitful.Unit{:Meter,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}(0, 1//1),),Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}}) at ./math.jl:475

The same issue occurs for @fastmath hypot, but does not occur when more arguments are passed: hypot(0m, 0m, 0m) evaluates to 0m.

Currently I get around this with:

function Base.hypot(x::Unitful.Quantity, y::Unitful.Quantity)
    if iszero(x) && iszero(y)
        return zero(x)
    else
        return hypot(x, y)
   end
end

but this is a band-aid, so I wanted to open this issue in case there is a better way.

@ajkeller34
Copy link
Collaborator

This is resolved when using the very latest Julia build and the master branch of Unitful. The next Unitful release will be for Julia 0.7 only.

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