Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.6, JRuby 1.6.7, JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: Core Classes/Modules
    • Labels:
      None
    • Environment:
    • Number of attachments :
      0

      Description

      Given the code:

      require 'date'
      e = Date.parse '2907-07-22'
      require 'bigdecimal'
      b = BigDecimal.new '1.0'
      rd = e - Date.today
      s = b / rd
      

      s is 3.05798240436925e-06 in MRI and JRuby --1.8 mode and nil in JRuby --1.9 mode.

      Is this correct or is it a bug?

        Activity

        Hide
        Thomas E Enebo added a comment -

        I cannot say what changed between 1.8 and 1.9 in MRI, but it will return an error in 1.9.3:

        ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]
        snippets/jruby-6556.rb:6:in `/': Rational can't be coerced into BigDecimal (TypeError)
        	from snippets/jruby-6556.rb:6:in `<main>'
        

        Assuming that is correct, then we should also be throwing a type error and not nil.

        Show
        Thomas E Enebo added a comment - I cannot say what changed between 1.8 and 1.9 in MRI, but it will return an error in 1.9.3: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0] snippets/jruby-6556.rb:6:in `/': Rational can't be coerced into BigDecimal (TypeError) from snippets/jruby-6556.rb:6:in `<main>' Assuming that is correct, then we should also be throwing a type error and not nil.
        Hide
        Thomas E Enebo added a comment -

        reduced case:

        require 'bigdecimal'
        
        a = Rational(1, 2)
        b = BigDecimal '1.0'
        p b / a
        
        Show
        Thomas E Enebo added a comment - reduced case: require 'bigdecimal' a = Rational(1, 2) b = BigDecimal '1.0' p b / a
        Hide
        Thomas E Enebo added a comment -

        Fixed in commit 693b9ef on master

        Show
        Thomas E Enebo added a comment - Fixed in commit 693b9ef on master
        Hide
        Uwe Kubosch added a comment -

        Thanks!

        Bummer that the difference between two dates is not a usable value for calculations. Having to convert from Rational to Integer/Float seems unnecessary.

        Show
        Uwe Kubosch added a comment - Thanks! Bummer that the difference between two dates is not a usable value for calculations. Having to convert from Rational to Integer/Float seems unnecessary.
        Hide
        Thomas E Enebo added a comment -

        The change seems somewhat intentional on MRI's part, but you might want to raise this issue on MRI's bug tracker or on ruby-core/talk to get a better answer.

        Show
        Thomas E Enebo added a comment - The change seems somewhat intentional on MRI's part, but you might want to raise this issue on MRI's bug tracker or on ruby-core/talk to get a better answer.

          People

          • Assignee:
            Thomas E Enebo
            Reporter:
            Uwe Kubosch
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: