BigDecimal#* returns Float (should be BigDecimal) #992

Closed
rob99 opened this Issue Sep 7, 2013 · 3 comments

3 participants

@rob99

MRI:

$ ruby -v 
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin11.4.2]
$ ruby -e 'require "bigdecimal";puts (BigDecimal.new(10) * 0.456).class'
BigDecimal

Using JRuby 1.7.4:

$ jruby -v
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_51-b11-457-11M4509 [darwin-x86_64]
$ jruby -e 'require "bigdecimal";puts (BigDecimal.new(10) * 0.456).class'
Float

Using JRuby 1.7.5 dev:

    $ java -jar jruby-complete-1.7.5.dev.jar -e 'require "bigdecimal";puts (BigDecimal.new(10) * 0.456).class'
    Float
    $ java -jar jruby-complete-1.7.5.dev.jar -v
    jruby 1.7.5.dev (1.9.3p392) 2013-09-06 294934d on Java HotSpot(TM) 64-Bit Server VM 1.6.0_51-b11-457-11M4509 [darwin-x86_64]

Fixnum appears to be ok:

$ jruby -e 'require "bigdecimal";puts (BigDecimal.new(10) * 9).class'
BigDecimal

Rational not so much:

# 1.7.4
$ jruby -e 'require "bigdecimal";puts (BigDecimal.new(10) * Rational(2,3)).class'
NilClass
$ java -jar jruby-complete-1.7.5.dev.jar -e 'require "bigdecimal";puts (BigDecimal.new(10) * Rational(2,3)).class'
NilClass
@rob99

Same problems with #+

$ ruby -e 'require "bigdecimal";puts (BigDecimal.new(10) + 0.123).class'
Float
@rob99

Error with #/(rational)

$ jruby -e 'require "bigdecimal";puts (BigDecimal.new(10) / Rational(2,3)).class'
ArgumentError: Rational can't be coerced into BigDecimal without a precision
   / at org/jruby/ext/bigdecimal/RubyBigDecimal.java:1057
 (root) at -e:1

Also

$ jruby -e 'require "bigdecimal";puts (BigDecimal.new(10) + Rational(2,3)).class'
TypeError: Rational can't be coerced into BigDecimal
   + at org/jruby/ext/bigdecimal/RubyBigDecimal.java:906
 (root) at -e:1
@atambo atambo was assigned Sep 7, 2013
@BanzaiMan
JRuby Team member

I assume f87088b is the last of fixes.

@BanzaiMan BanzaiMan closed this Sep 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment