From: sawadatsuyoshi@... Date: 2019-06-05T08:33:53+00:00 Subject: [ruby-core:92975] [Ruby trunk Bug#15857] <=> の右辺が <=> を実装していない場合の振る舞い Issue #15857 has been updated by sawa (Tsuyoshi Sawada). jeremyevans0 (Jeremy Evans) wrote: > I think [that] Complex numbers with an imaginary part of zero should be treated as real numbers, and that `Complex#real?` should return `true` for such numbers. Changing `Complex#real?`'s meaning has huge influence. You would also have to change `Numeric#integer?` for consistency. Notice that in Ruby, there is no class `Real`, and `real?` means "not an instance of `Complex`". I believe `Float` is an approximation of the concept of real numbers in mathematics, but unfortunately, `Integer` and `Rational` are not subclasses of `Float` like integers and rational numbers are subsets of real numbers in the mathematical sense. So discussing your proposal in terms of real numbers does not look that helpful. > `Complex#<=>` should return 1, 0, or -1 if both the receiver and the argument are real numbers (treating Complex instances with an imaginary part of zero as real numbers). I think this should rather be handled by coercion as with arithmetic operations. ---------------------------------------- Bug #15857: <=> ������������ <=> ��������������������������������������������� https://bugs.ruby-lang.org/issues/15857#change-78352 * Author: shuujii (Shuji KOBAYASHI) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- `<=>` ������������ `<=>` ���������������������������������`nil` ��������������������������������������������������������������������������������������������������������������������������������������������� ```ruby 0 <=> 0i #=> NoMethodError (undefined method `<=>' for (0+0i):Complex) 0 <=> BasicObject.new #=> nil :a <=> 0i #=> nil "a" <=> 0i #=> NoMethodError (undefined method `<=>' for (0+0i):Complex) ``` ���������`0 <=> 0i` ������������������`0 == 0i` ��� `true` ��������������������������������������������������������������������������������������������������� ---Files-------------------------------- complex-real-spaceship.patch (8.75 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: