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

Potential For Infinite Loop in Real .polymod Due To Floating Point Math Imprecision #5326

Closed
p6rt opened this issue May 18, 2016 · 3 comments
Closed

Comments

@p6rt
Copy link

@p6rt p6rt commented May 18, 2016

Migrated from rt.perl.org#128175 (status was 'rejected')

Searchable as RT128175$

@p6rt
Copy link
Author

@p6rt p6rt commented May 18, 2016

From @zoffixznet

Current implementation of .polymod on Reals with lazy list divisors as arguments checks for whether the number operated on is exactly equals to zero before stopping​: https://github.com/rakudo/rakudo/blob/51bbf66a34ae8208e6aa8f76347579bd70c34748/src/core/Real.pm#L73

This creates a potential for an infinite loop due to floating point math imprecision that introduces differences between the remained subtracted from the number and the resulting division. I believe the check should be changed from `last if $inf and not $more;` to `last if $inf and $more <= 0;`.

Here is an example of the issue​:

  $ perl6 -e 'say 4343434343.Num.polymod​: 1/3 xx Inf'
  (2.41212546825409e-07 7.23637640476227e-07 2.16811895370483e-06 6.51180744171143e-06 1.95205211639404e-05 5.8591365814209e-05 0.000175714492797852 0.000527381896972656 0.00158119201660156 0.0047454833984375 0.0142364501953125 0.042724609375 0.128173828125 0.05126953125 1.15234375 -1.875 10.375 -32.875 -77.25 280 -1207 2524 -3360 864 68096 29440 613376 1839104 5513216 -17006592 4915200 148897792 -268959744 -92274688 -1707081728 603979776 36171677696 108582141952 325880643584 977105059840 -2933462663168 8796093022208 26388279066624 -14705968021504 -325455441821696 -38482906972160 2.13745060439654e+15 -1.16020466962924e+16 1.92458515325911e+16 5.77023702256845e+16 1.73107110677053e+17 -6.33881647552397e+17 1.55824547107019e+18 4.67473641321057e+18 1.4015202040377e+19 4.20816349181499e+19 -1.68903000424903e+20 -1.4987979559889e+19 -4.38110171750602e+20 -2.89152713355397e+21 -2.37962998550853e+21 -1.97011226707218e+22 -8.70686320279091e+21 -1.26913599227122e+23 8.27594726122905e+23 2.48396476998943e+24 1.00114169436836e+24 -3.4378827995291e+24 -8.76471219220606e+25 -5.13793473336217e+24 -6.3468605529768e+26 -1.48939660976522e+27 -1.17024019338696e+27 1.62866486418483e+28 -3.94593387522215e+27 4.10067638013282e+28 4.40087683965953e+29 1.31964408187822e+30 5.79355938385558e+29 -1.64398437217099e+30 -1.84601618658236e+31 1.06958019394257e+32 -1.11870165470141e+32 9.62146805573226e+32 2.88517276611945e+33 8.66058890075926e+33 2.59614842926741e+34 -3.28575035579157e+34 -4.30636120704732e+35 7.00960075902202e+35 2.10547637613587e+36 6.31383297997835e+36 4.7561439224179e+36 5.68244968198052e+37 1.70473490459415e+38 -3.96109942743905e+38 1.53392910713579e+39 4.60444577739895e+39 -7.01832381774436e+38 -1.6673835979126e+40 ...)
 
  $ perl6 -e 'put 4343434343.Num.polymod​: 1/3 xx Inf'
  ^C # an nearly infinite loop

@p6rt
Copy link
Author

@p6rt p6rt commented Jul 17, 2016

From @zoffixznet

Rejecting this. The 1/3 divisor doesn't make sense, as it will be making the original number larger and larger and I can't reproduce any issues with a sane divisor.

@p6rt
Copy link
Author

@p6rt p6rt commented Jul 17, 2016

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

@p6rt p6rt closed this Jul 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.