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

Fix rational division by zero #40551

Merged
merged 4 commits into from
Apr 21, 2021
Merged

Conversation

blegat
Copy link
Contributor

@blegat blegat commented Apr 21, 2021

On Julia v1.5.3:

julia> a = big(1 // 1)
1//1

julia> a / zero(a)
1//0

On Julia v1.6.0

julia> a = big(1 // 1)
1//1

julia> a / zero(a)
ERROR: MethodError: no method matching //(::BigFloat, ::BigInt)
Closest candidates are:
  //(::Integer, ::Integer) at rational.jl:61
  //(::Rational, ::Integer) at rational.jl:63
  //(::Complex, ::Real) at rational.jl:77
simonbyrne   ...
Stacktrace:
 [1] //(x::Rational{BigInt}, y::Rational{BigInt})
   @ Base.GMP.MPQ ./gmp.jl:934
 [2] /(x::Rational{BigInt}, y::Rational{BigInt})
   @ Base ./rational.jl:321
 [3] top-level scope
   @ REPL[2]:1

It seems the line was not covered by tests so the PR both fixes the error and adds some tests.

Note that the behavior is still different from Julia v1.5.3 but there is no error and it seems to be the behavior intended by @simonbyrne in #38520

base/gmp.jl Outdated Show resolved Hide resolved
@sostock sostock added backport 1.6 Change should be backported to release-1.6 bugfix This change fixes an existing bug labels Apr 21, 2021
@sostock
Copy link
Contributor

sostock commented Apr 21, 2021

The test failures are due to the type-instability (before this PR, the BigFloat-branch of the method always errored, so it didn’t affect the return type).

Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
test/gmp.jl Outdated Show resolved Hide resolved
test/gmp.jl Outdated Show resolved Hide resolved
blegat and others added 2 commits April 21, 2021 15:58
Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
Copy link
Contributor

@simonbyrne simonbyrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@simonbyrne simonbyrne merged commit 2307f80 into JuliaLang:master Apr 21, 2021
KristofferC pushed a commit that referenced this pull request May 4, 2021
* Fix rational division by zero
* Replace `BigFloat` by `BigInt`

Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
(cherry picked from commit 2307f80)
@KristofferC KristofferC mentioned this pull request May 4, 2021
45 tasks
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
* Fix rational division by zero
* Replace `BigFloat` by `BigInt`

Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request May 9, 2021
* Fix rational division by zero
* Replace `BigFloat` by `BigInt`

Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
* Fix rational division by zero
* Replace `BigFloat` by `BigInt`

Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
@KristofferC KristofferC removed the backport 1.6 Change should be backported to release-1.6 label Jul 12, 2021
staticfloat pushed a commit that referenced this pull request Dec 23, 2022
* Fix rational division by zero
* Replace `BigFloat` by `BigInt`

Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
(cherry picked from commit 2307f80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants