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

Infinite recursion in div for Real #33651

Closed
iamed2 opened this issue Oct 23, 2019 · 4 comments · Fixed by #33679
Closed

Infinite recursion in div for Real #33651

iamed2 opened this issue Oct 23, 2019 · 4 comments · Fixed by #33679
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@iamed2
Copy link
Contributor

iamed2 commented Oct 23, 2019

#33040 caused this

The fallback div definition used to apply to T <: Real but is now for T <: AbstractFloat, which leaves out types such as FixedPointDecimal. This causes an infinite promote recursion.

julia> using FixedPointDecimals

julia> a = FixedDecimal{Int,1}(1.3)
FixedDecimal{Int64,1}(1.3)

julia> div(a, a, RoundToZero)
ERROR: StackOverflowError:
Stacktrace:
 [1] div(::FixedDecimal{Int64,1}, ::FixedDecimal{Int64,1}, ::RoundingMode{:ToZero}) at ./div.jl:234 (repeats 79985 times)
@ararslan ararslan added bug Indicates an unexpected problem or unintended behavior regression Regression in behavior compared to a previous version labels Oct 25, 2019
@Keno
Copy link
Member

Keno commented Oct 25, 2019

Yes, the removal of the fallback was deliberate. It was widely inaccurate for various types we had. FixedPointDecimals should provide this method for its particular type. Of course we should fix this to give a better error.

@Keno
Copy link
Member

Keno commented Oct 26, 2019

Also, I don't think this is a regression, at least not as stated. Three argument div is new as of that commit.

@Keno Keno removed the regression Regression in behavior compared to a previous version label Oct 26, 2019
Keno added a commit that referenced this issue Oct 26, 2019
also a better compatibility fallback to two-argument div for packages
that haven't upgraded yet.

Fixes #33651
Keno added a commit that referenced this issue Oct 26, 2019
also a better compatibility fallback to two-argument div for packages
that haven't upgraded yet.

Fixes #33651
Keno added a commit that referenced this issue Oct 28, 2019
also a better compatibility fallback to two-argument div for packages
that haven't upgraded yet.

Fixes #33651
@NHDaly
Copy link
Member

NHDaly commented Oct 31, 2019

Ah, @Keno, it turns out that there was actually a regression, since the default implementation of ÷ had changed in #33040 to call 3-argument div. So this was now failing, where it didn't fail before:

julia> let x = FixedDecimal{Int,2}(1)
           x ÷ 2
       end
ERROR: StackOverflowError:
Stacktrace:
 [1] div(::FixedDecimal{Int64,2}, ::FixedDecimal{Int64,2}, ::RoundingMode{:ToZero}) at ./div.jl:234 (repeats 79998 times)

But your new fallback definition in #33679 does indeed fix the regression, so thanks! :)

julia> let x = FixedDecimal{Int,2}(1)
           x ÷ 2
       end
FixedDecimal{Int64,2}(0.00)

@Keno
Copy link
Member

Keno commented Oct 31, 2019

Yeah, I saw that after making that comment and testing my fixed so I fixed it right along the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants