Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtracting nil from a BigDecimal returns nil #1441

Closed
nmk opened this Issue Jan 24, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@nmk
Copy link

commented Jan 24, 2014

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

require "bigdecimal"
BigDecimal.new("0") - nil # => nil

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

@eldritchideen

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2014

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/RubyBigDecimal.java b/core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.j
index 875a4b3..4a616c7 100644
--- a/core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
+++ b/core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
@@ -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) {
@enebo

This comment has been minimized.

Copy link
Member

commented Jan 27, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.