You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I defined a Liter unit based on 1000cm^3, and it seemed to work most of the time, but then failed on some operations. If I instead define it based on m^3, then it seems to work as expected. I added the following lines to Defaults.jl to test this:
And then did the following tests at the REPL that all work.
julia> a =1u"altL"1 altL
julia> a =1u"maltL"1 maltL
julia>dimension(a)
𝐋^3
But then trying to get back to a unitless number fails
julia>Float64(1u"altL/cm^3")
ERROR: DomainError:
Cannot raise an integer x to a negative power -n.
Make x a float by adding a zero decimal (e.g. 2.0^-n instead of 2^-n), or write 1/x^n, float(x)^-n, or (x//1)^-n.
inpower_by_squaring(::Int64, ::Int64) at ./intfuncs.jl:118inbasefactorhelper(::Float64, ::Int64, ::Int64, ::Rational{Int64}) at /Users/oneilg/.julia/v0.5/Unitful/src/Unitful.jl:268inmap(::Unitful.#basefactor, ::Tuple{Unitful.Unit{:Meter},Unitful.Unit{:altLiter}}) at ./tuple.jl:93inbasefactor(...) at /Users/oneilg/.julia/v0.5/Unitful/src/Unitful.jl:276inconvfact(...) at /Users/oneilg/.julia/v0.5/Unitful/src/Conversion.jl:85in convert at /Users/oneilg/.julia/v0.5/Unitful/src/Conversion.jl:183 [inlined]
inFloat64(::Unitful.Quantity{Int64,Unitful.Dimensions{()},Unitful.Units{(Unitful.Unit{:Meter}(-2,-3//1),Unitful.Unit{:altLiter}(0,1//1)),Unitful.Dimensions{()}}}) at ./sysimg.jl:53
The version based on m^3 works for going to a unitless number
julia>Float64(1u"L/cm^3")
1000.0
And arb (based on nA) shows the same error as altL
julia>Float64(1u"arb/A")
ERROR: DomainError:
Cannot raise an integer x to a negative power -n.
Make x a float by adding a zero decimal (e.g. 2.0^-n instead of 2^-n), or write 1/x^n, float(x)^-n, or (x//1)^-n.
inpower_by_squaring(::Int64, ::Int64) at ./intfuncs.jl:118inbasefactorhelper(::Float64, ::Int64, ::Int64, ::Rational{Int64}) at /Users/oneilg/.julia/v0.5/Unitful/src/Unitful.jl:268inmap(::Unitful.#basefactor, ::Tuple{Unitful.Unit{:Ampere},Unitful.Unit{:Arb}}) at ./tuple.jl:93inbasefactor(...) at /Users/oneilg/.julia/v0.5/Unitful/src/Unitful.jl:276inconvfact(...) at /Users/oneilg/.julia/v0.5/Unitful/src/Conversion.jl:85in convert at /Users/oneilg/.julia/v0.5/Unitful/src/Conversion.jl:183 [inlined]
inFloat64(::Unitful.Quantity{Int64,Unitful.Dimensions{()},Unitful.Units{(Unitful.Unit{:Ampere}(0,-1//1),Unitful.Unit{:Arb}(0,1//1)),Unitful.Dimensions{()}}}) at ./sysimg.jl:53
The text was updated successfully, but these errors were encountered:
Fixed on master and added a test for this condition. The fix will be included in next release or you can Pkg.checkout("Unitful") if you want to be on master.
mdavezac
pushed a commit
to mdavezac/Unitful.jl
that referenced
this issue
Oct 30, 2016
I defined a Liter unit based on 1000cm^3, and it seemed to work most of the time, but then failed on some operations. If I instead define it based on m^3, then it seems to work as expected. I added the following lines to
Defaults.jl
to test this:And then did the following tests at the REPL that all work.
But then trying to get back to a unitless number fails
The version based on m^3 works for going to a unitless number
And arb (based on nA) shows the same error as altL
The text was updated successfully, but these errors were encountered: