Skip to content

Commit cad1ca4

Browse files
committed
[GR-18163] Ruby 2.7: Add Complex#<=> (#2161)
PullRequest: truffleruby/2170
2 parents 666041d + 0b9e9e7 commit cad1ca4

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Compatibility:
1818
* Implement `Range#minmax`.
1919
* Pass more `Enumerator::Lazy#uniq` and `Enumerator::Lazy#chunk` specs (#2146, @LillianZ).
2020
* Implement `Enumerator#produce` (#2160, @zverok)
21+
* Implement `Complex#<=>` (#2004, @ssnickolay).
2122

2223
Performance:
2324

spec/tags/core/complex/comparision_tags.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/main/ruby/truffleruby/core/complex.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
class Complex < Numeric
3838

39-
undef_method :%, :<, :<=, :<=>, :>, :>=, :between?, :clamp, # comparable
39+
undef_method :%, :<, :<=, :>, :>=, :between?, :clamp, # comparable
4040
:div, :divmod, :floor, :ceil, :modulo, :remainder,
4141
:round, :step, :truncate, :i, :negative?, :positive?
4242

@@ -373,6 +373,16 @@ def marshal_load(ary)
373373
self
374374
end
375375

376+
def <=>(other)
377+
if imag == 0 && other.kind_of?(Numeric)
378+
if other.kind_of?(Complex) && other.imag == 0
379+
real <=> other.real
380+
elsif other.real?
381+
real <=> other
382+
end
383+
end
384+
end
385+
376386
I = Complex(0, 1)
377387

378388
end

test/mri/excludes/Complex_Test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@
1616
exclude :test_rationalize, "needs investigation"
1717
exclude :test_Complex_with_invalid_exception, "needs investigation"
1818
exclude :test_conv, "needs investigation"
19-
exclude :test_cmp, "needs investigation"

0 commit comments

Comments
 (0)