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

Overflow in conversion #430

Closed
aplavin opened this issue Mar 10, 2021 · 1 comment · Fixed by #741
Closed

Overflow in conversion #430

aplavin opened this issue Mar 10, 2021 · 1 comment · Fixed by #741

Comments

@aplavin
Copy link
Contributor

aplavin commented Mar 10, 2021

I saw several old issues regarding overflow exceptions, but looks like they are considered solved. However, I experience the following:

using Unitful, UnitfulAstro

julia> 1.0u"GHz^2 * J * c^-2" |> u"Jy / arcsecond^2"
ERROR: OverflowError: 22468879468420441 * 51840 overflowed for type Int64

julia> uconvert(u"Jy / arcsecond^2", 1.0u"GHz^2 * J * c^-2")
ERROR: OverflowError: 22468879468420441 * 51840 overflowed for type Int64

julia> 1.0u"GHz^2 * J * c^-2" |> upreferred |> u"Jy / arcsecond^2"
2.6152205956835644e16 Jy ″^-2

That is, conversion only works with an intermediate upreferred. I couldn't find a similar example with default Unitful units without other packages, but it should be possible.

Is there a way to force floating-point conversion instead of exact ones?

Stacktrace points to this line: https://github.com/PainterQubits/Unitful.jl/blob/master/src/conversion.jl#L22, which even mentions overflow checking :) But it's not really clear how to fix the error.
Full error:

ERROR: OverflowError: 22468879468420441 * 51840 overflowed for type Int64
Stacktrace:
  [1] throw_overflowerr_binaryop(op::Symbol, x::Int64, y::Int64)
    @ Base.Checked ./checked.jl:154
  [2] checked_mul
    @ ./checked.jl:288 [inlined]
  [3] //(x::Rational{Int64}, y::Int64)
    @ Base ./rational.jl:65
  [4] #s57#154
    @ ~/.julia/packages/Unitful/JwSBO/src/conversion.jl:22 [inlined]
  [5] var"#s57#154"(::Any, s::Any, t::Any)
    @ Unitful ./none:0
  [6] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any, N} where N)
    @ Core ./boot.jl:571
  [7] uconvert(a::Unitful.FreeUnits{(″^-2, Jy), 𝐌 𝐓^-2, nothing}, x::Quantity{Float64, 𝐌 𝐓^-2, Unitful.FreeUnits{(GHz^2, J, c^-2), 𝐌 𝐓^-2, nothing}})
    @ Unitful ~/.julia/packages/Unitful/JwSBO/src/conversion.jl:78
  [8] FreeUnits
    @ ~/.julia/packages/Unitful/JwSBO/src/types.jl:97 [inlined]
  [9] |>(x::Quantity{Float64, 𝐌 𝐓^-2, Unitful.FreeUnits{(GHz^2, J, c^-2), 𝐌 𝐓^-2, nothing}}, f::Unitful.FreeUnits{(″^-2, Jy), 𝐌 𝐓^-2, nothing})
    @ Base ./operators.jl:859
 [10] top-level scope
    @ REPL[5]:1
@Socob
Copy link
Contributor

Socob commented Oct 7, 2024

This was fixed in #648 (present in v1.16.1, but not anymore since v1.16.2).

sostock pushed a commit that referenced this issue Oct 30, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants