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

Int8(8) // Int8(100)im == -50im due to overflow #53435

Open
nhz2 opened this issue Feb 22, 2024 · 1 comment · May be fixed by #56478
Open

Int8(8) // Int8(100)im == -50im due to overflow #53435

nhz2 opened this issue Feb 22, 2024 · 1 comment · May be fixed by #56478
Labels
bug Indicates an unexpected problem or unintended behavior complex Complex numbers correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing rationals The Rational type and values thereof

Comments

@nhz2
Copy link
Contributor

nhz2 commented Feb 22, 2024

The current method for // on Integer and Complex{<:Integer} can overflow, silently giving an incorrect answer. For example:

julia> Int8(8) // Int8(100)im
0//1 - 50//1*im

The expected answer is 0//1 - 2//25*im

The issue is caused by abs2 and conj on Complex{Int8} silently overflowing in:

//(x::Number, y::Complex) = x*conj(y)//abs2(y)

One solution could be to specialize this method on the many different combinations of Complex{<:Rational}, Complex{<:Integer}, Rational, Integer, and Number for the inputs, and check for overflow when doing any Integer math. Maybe there is a nicer way to fix this issue.

@nhz2 nhz2 added bug Indicates an unexpected problem or unintended behavior rationals The Rational type and values thereof complex Complex numbers labels Feb 22, 2024
@nhz2 nhz2 changed the title Int8(8) // Int8(100)im == -50im do to overflow Int8(8) // Int8(100)im == -50im due to overflow Feb 22, 2024
@LilithHafner LilithHafner added the correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing label Apr 22, 2024
@nsajko
Copy link
Contributor

nsajko commented Oct 19, 2024

The offending oneliner is buggy in other ways, too: #56245.

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 complex Complex numbers correctness bug ⚠ Bugs that are likely to lead to incorrect results in user code without throwing rationals The Rational type and values thereof
Projects
None yet
3 participants