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

int * int gives wrong result on large values #5729

Closed
p6rt opened this issue Oct 5, 2016 · 3 comments
Closed

int * int gives wrong result on large values #5729

p6rt opened this issue Oct 5, 2016 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 5, 2016

Migrated from rt.perl.org#129813 (status was 'resolved')

Searchable as RT129813$

@p6rt
Copy link
Author

p6rt commented Oct 5, 2016

From @zoffixznet

# I have the fix; filing for records

If large-enough values are used for multiplication, we get 0 instead
of correct results​:

<Zoffix> m​: say (my int $ = 2**32) * (my int $ = 2**63)
<camelia> rakudo-moar 62d838​: OUTPUT«0␤»
<Zoffix> m​: say (my int $ = 2**62) * (my int $ = 2**62)
<camelia> rakudo-moar 62d838​: OUTPUT«0␤»

The fix is to add `or $a == 0 || $b == 0 ?? 0 !!
Failure.new(X​::Numeric​::Overflow.new)` after the calculation in
https://github.com/rakudo/rakudo/blob/62d8382/src/core/Int.pm#L262

However, that currently won't work entirely due to RT#​129811​:
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129811

@p6rt
Copy link
Author

p6rt commented Oct 6, 2016

From @zoffixznet

Fixed in rakudo/rakudo@8023dfbc6f
Test in Raku/roast@22408595d6

On Wed Oct 05 14​:43​:38 2016, cpan@​zoffix.com wrote​:

# I have the fix; filing for records

If large-enough values are used for multiplication, we get 0 instead
of correct results​:

<Zoffix> m​: say (my int $ = 2**32) * (my int $ = 2**63)
<camelia> rakudo-moar 62d838​: OUTPUT«0␤»
<Zoffix> m​: say (my int $ = 2**62) * (my int $ = 2**62)
<camelia> rakudo-moar 62d838​: OUTPUT«0␤»

The fix is to add `or $a == 0 || $b == 0 ?? 0 !!
Failure.new(X​::Numeric​::Overflow.new)` after the calculation in
https://github.com/rakudo/rakudo/blob/62d8382/src/core/Int.pm#L262

However, that currently won't work entirely due to RT#​129811​:
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129811

@p6rt
Copy link
Author

p6rt commented Oct 6, 2016

@zoffixznet - Status changed from 'new' to 'resolved'

@p6rt p6rt closed this as completed Oct 6, 2016
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant