Skip to content

Subtracting nil from a BigDecimal returns nil #1441

nmk opened this Issue Jan 24, 2014 · 2 comments

3 participants

nmk commented Jan 24, 2014

Under JRuby 1.7.9 and 1.7.10 the following expression evaluates to nil.

require "bigdecimal""0") - nil # => nil

It raises a TypeError under MRI 2.0, which is the behaviour I would expect.


I had a quick look at the Java code that implements BigDecimal and the "-" binary operator. It seems to be a simple fix. See the code below. With this change, the output seems to be the same between JRuby and MRI. I have submitted a pull request for this change. #1442

diff --git a/core/src/main/java/org/jruby/ext/bigdecimal/ b/core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.j
index 875a4b3..4a616c7 100644
--- a/core/src/main/java/org/jruby/ext/bigdecimal/
+++ b/core/src/main/java/org/jruby/ext/bigdecimal/
@@ -798,7 +798,7 @@ public class RubyBigDecimal extends RubyNumeric {

     @JRubyMethod(name = "-", required = 1)
     public IRubyObject op_minus19(ThreadContext context, IRubyObject b) {
-        return subInternal(context, getVpValue19(context, b, false), b);
+        return subInternal(context, getVpValue19(context, b, true), b);

     public IRubyObject sub2(ThreadContext context, IRubyObject b, IRubyObject n) {
JRuby Team member
enebo commented Jan 27, 2014

This was fixed by PR #1442. Resolving. Thanks for reporting and figuring out the right fix.

@enebo enebo closed this Jan 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.