Backport #2349

lib/bigdecimal: errors in comparisons [patch]

Added by marcandre (Marc-Andre Lafortune) over 2 years ago. Updated about 1 year ago.

[ruby-core:26646]
Status:Closed Start date:11/09/2009
Priority:Normal Due date:
Assignee:wyhaines (Kirk Haines) % Done:

100%

Category:-
Target version:-

Description

$ ruby -r bigdecimal -e 'p BigDecimal.new("1") < nil'
nil

expected: an error like with any other mathematical type:
-e:1:in `<': comparison of BigDecimal with nil failed (ArgumentError)

--------------
$ ruby -r bigdecimal -e 'p BigDecimal.new("1") == nil'
nil

expected: false like with any other Ruby object

--------------
$ ruby -r bigdecimal -e 'p BigDecimal.new("NaN") < 1'
nil

expected: false, like with any other mathematical comparison


I'll commit the attached patch in a few days (for 1.8 & 1.9) unless there are arguments against it.

bigdec.diff (2.4 kB) marcandre (Marc-Andre Lafortune), 11/09/2009 03:33 pm

Associated revisions

Revision 25765
Added by marcandre (Marc-Andre Lafortune) over 2 years ago

* ext/bigdecimal/bigdecimal.c (BigDecimalCmp): Fix comparisons [ruby-core:26646] * test/bigdecimal/test_bigdecimal.rb (class): Fix and improve tests.

Revision 29025
Added by wyhaines almost 2 years ago

ext/bigdecimal/bigdecimal.c: Backport #2349 [ruby-core:26646]; fix comparisons. Also fix a bunch of bugs that lead to broken-ness and failing tests. test/bigdecimal/test_bigdecimal.rb: Backport #2349 [ruby-core:26646]; added a test suite. test/ruby/test_exception.rb: The test suite was breaking ZeroDivisionError, which in turn would break bigdecimal/test_bigdecimal.rb. Made a simple fix that keeps that test but does so non-destructively.

History

Updated by marcandre (Marc-Andre Lafortune) over 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r25765.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Updated by shyouhei (Shyouhei Urabe) about 2 years ago

  • Status changed from Closed to Assigned
  • Assignee changed from marcandre (Marc-Andre Lafortune) to shyouhei (Shyouhei Urabe)

Updated by shyouhei (Shyouhei Urabe) about 2 years ago

  • Assignee changed from shyouhei (Shyouhei Urabe) to wyhaines (Kirk Haines)
Well, a litte inspection shows me that
* 1.9.2dev, 1.8.8dev, and 1.8.7 behave in the same way (as marcandre expected)
* 1.9.1, and 1.8.6 behave as described in the original post

So I suspect 1.9.1 and 1.8.6 are buggy here, both should backport this.

Updated by wyhaines (Kirk Haines) almost 2 years ago

  • Status changed from Assigned to Closed
This issue was solved with changeset r29025.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF