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
Apologies for the contrived examples, but this is only an issue for units with an “inexact” conversion part != 1.0, and becomes more serious the more different it is from 1. Originally, I ran into this in the context of astrophysical units (see JuliaAstro/UnitfulAstro.jl#33), but I wanted to give a more minimal example with “built-in” units.
# Note that sometimes x^1 can cause an overflow error if x is large because
# of how power_by_squaring is implemented for Rationals, so we use dpow.
x =dpow(eq*ex*(10//1)^tens, p)
return (inex^p, isinteger(x) ?Int(x) : x)
else
x =dpow(ex*(10//1)^tens, p)
return ((inex*eq)^p, isinteger(x) ?Int(x) : x)
end
else
if eq_is_exact && can_exact2
x =dpow(eq,p)
return ((inex * ex *10.0^tens)^p, isinteger(x) ?Int(x) : x)
else
return ((inex * ex *10.0^tens * eq)^p, 1)
end
end
can result in Inf (inex > 1) or 0.0 (inex < 1) for large p, even though all the large factors end up canceling in the conversion. Ideally, uconvert() would be smarter and avoid dividing these canceling huge/tiny factors, but at a bare minimum, this should give an error instead of silently returning something wrong!
The text was updated successfully, but these errors were encountered:
Apologies for the contrived examples, but this is only an issue for units with an “inexact” conversion part
!= 1.0
, and becomes more serious the more different it is from 1. Originally, I ran into this in the context of astrophysical units (see JuliaAstro/UnitfulAstro.jl#33), but I wanted to give a more minimal example with “built-in” units.The issue is that
inex^p
inbasefactor()
:Unitful.jl/src/units.jl
Lines 229 to 247 in bd09747
can result in
Inf
(inex > 1
) or0.0
(inex < 1
) for largep
, even though all the large factors end up canceling in the conversion. Ideally,uconvert()
would be smarter and avoid dividing these canceling huge/tiny factors, but at a bare minimum, this should give an error instead of silently returning something wrong!The text was updated successfully, but these errors were encountered: