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

rem and div overflow unexpectedly for Rational #36423

Open
simeonschaub opened this issue Jun 24, 2020 · 3 comments
Open

rem and div overflow unexpectedly for Rational #36423

simeonschaub opened this issue Jun 24, 2020 · 3 comments

Comments

@simeonschaub
Copy link
Member

simeonschaub commented Jun 24, 2020

These probably shouldn't overflow:

julia> rem(1//typemax(Int), 2)
ERROR: OverflowError: 9223372036854775807 * 2 overflowed for type Int64
Stacktrace:
 [1] throw_overflowerr_binaryop(::Symbol, ::Int64, ::Int64) at ./checked.jl:173
 [2] checked_mul at ./checked.jl:307 [inlined]
 [3] rem(::Rational{Int64}, ::Int64) at ./rational.jl:288
 [4] top-level scope at REPL[9]:1

julia> div(1//typemax(Int), 2)
ERROR: OverflowError: 9223372036854775807 * 2 overflowed for type Int64
Stacktrace:
 [1] throw_overflowerr_binaryop(::Symbol, ::Int64, ::Int64) at ./checked.jl:173
 [2] checked_mul at ./checked.jl:307 [inlined]
 [3] div(::Rational{Int64}, ::Int64, ::RoundingMode{:ToZero}) at ./rational.jl:407
 [4] div(::Rational{Int64}, ::Int64) at ./rational.jl:425
 [5] top-level scope at REPL[10]:1

Maybe a it's enough to just check if the first argument is smaller than the second one, and in that case just return the first argument/0.

@StefanKarpinski
Copy link
Member

The denominator in the div case is too large to be represented. The rem operation could be made to work.

@simeonschaub
Copy link
Member Author

div(1//typemax(Int), 2) ist just 0, no?

@StefanKarpinski
Copy link
Member

StefanKarpinski commented Jun 25, 2020

Ah, true. I was thinking (1//typemax(Int))/2 which is not zero, of course. Carry on!

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