JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6131

Integer#round can effectively hang jruby for large negative arguments in --1.9 mode

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: JRuby 1.6.6, JRuby 1.7.0.pre1
    • Component/s: Intro
    • Labels:
      None
    • Environment:
      --1.9
    • Number of attachments :
      0

      Description

      jruby --1.9 -e '42.round(-2**30)'

      This will cheerfully consume a thread's worth of cpu more or less indefinitely. Impatient users will need kill -9 to recover.

      mri 1.9.2 returns 0.0 without any difficulty.

        Activity

        Hide
        Hiro Asari added a comment -

        This is because MRI has short circuit logic to return 0 if the argument is small enough.

        https://github.com/ruby/ruby/blob/0a5ac6a44809ec32ae6e836086708a64112bcfd0/numeric.c#L1469-1472

        This should be pretty easy to fix.

        Show
        Hiro Asari added a comment - This is because MRI has short circuit logic to return 0 if the argument is small enough. https://github.com/ruby/ruby/blob/0a5ac6a44809ec32ae6e836086708a64112bcfd0/numeric.c#L1469-1472 This should be pretty easy to fix.
        Hide
        Martin Harriman added a comment -

        There's a similar divergence in the underlying computation:

        ruby -e "puts 10*(2*30)" prints "Infinity"

        jruby -e "puts 10*(2*30)" runs indefinitely
        jruby -e "puts 10.0*(2*30)" prints "Infinity"

        Show
        Martin Harriman added a comment - There's a similar divergence in the underlying computation: ruby -e "puts 10* (2 *30)" prints "Infinity" jruby -e "puts 10* (2 *30)" runs indefinitely jruby -e "puts 10.0* (2 *30)" prints "Infinity"
        Hide
        Hiro Asari added a comment -

        I fixed this recently. 77838ecf or thereabouts.

        Show
        Hiro Asari added a comment - I fixed this recently. 77838ecf or thereabouts.

          People

          • Assignee:
            Hiro Asari
            Reporter:
            Martin Harriman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: