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

Powering operation of Integer sometimes gets a wrong calculation when 1.9 mode.

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.5
    • Fix Version/s: JRuby 1.6.6, JRuby 1.7.0.pre1
    • Component/s: Core Classes/Modules
    • Labels:
      None
    • Environment:
      jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_23) [Windows 7-amd64-java]
    • Number of attachments :
      0

      Description

      ex)
      jruby --1.9 -e "p 1539948653 ** 2"
      -> 4561929911295338257 (wrong)

      jruby --1.9 -e "p 1539948653 * 1539948653"
      -> 2371441853876514409 (correct)

        Activity

        Hiro Asari made changes -
        Field Original Value New Value
        Assignee Hiro Asari [ asari ]
        Hide
        Hiro Asari added a comment - - edited

        This is a rather peculiar problem.

        Note https://github.com/jruby/jruby/blob/81cd13e2fe6ee2f87b769851aeefedb626091e96/src/org/jruby/util/Numeric.java#L476

        Under some circumstances, this test evaluates to false unexpectedly (because x*x overflows the 'long' range and ends up in just the right range) and we return a wrong value. (The smallest integer for which this happens is 854374.)

        This is fixed in e93fc5a on master and ddfe667 on the 1.6 branch.

        Show
        Hiro Asari added a comment - - edited This is a rather peculiar problem. Note https://github.com/jruby/jruby/blob/81cd13e2fe6ee2f87b769851aeefedb626091e96/src/org/jruby/util/Numeric.java#L476 Under some circumstances, this test evaluates to false unexpectedly (because x*x overflows the 'long' range and ends up in just the right range) and we return a wrong value. (The smallest integer for which this happens is 854374.) This is fixed in e93fc5a on master and ddfe667 on the 1.6 branch.
        Hiro Asari made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s JRuby 1.6.6 [ 18033 ]
        Fix Version/s JRuby 1.7 [ 17049 ]
        Resolution Fixed [ 1 ]
        Charles Oliver Nutter made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Hiro Asari
            Reporter:
            Yasunori Miyamoto
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: