From: Robert Klemme Date: 2009-12-21T00:15:05+09:00 Subject: Re: Correcting complex math On 20.12.2009 15:51, Colin Bartlett wrote: > I'd also like to take the opportunity of this thread > to suggest removing (!) something from Complex, > unless anyone can make a good case for retaining it: > The Complex numbers are not an "ordered field", > at least not in any normally useful sense. > > At the moment if either x or y is Complex > then x <=> y is calculated as x.abs <=> y.abs; > > # File complex.rb, line 312 > def <=> (other) > self.abs <=> other.abs > end > > I think that can be misleading (see the examples above), > and I would prefer it if "<=>" and "<", etc, > were *not* defined for Complex, > and if one wants to compare absolute values > then one should do so explicitly. Done. robert@fussel ~ $ allruby -r complex -e 'p Complex(1,-1) <=> Complex(-1,1)' ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] 0 ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-cygwin] -e:1:in `
': undefined method `<=>' for (1-1i):Complex (NoMethodError) robert@fussel ~ $ :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/