From: Paul Smith Date: 2009-12-21T00:03:06+09:00 Subject: Re: Correcting complex math On Sun, Dec 20, 2009 at 2:51 PM, Colin Bartlett wrote: > If this can be made to work, it might be useful. > Two thoughts that occur to me are: > > 1. The code you show would probably need to use Rational(?), >   otherwise 1/n (or 1.0/n) may not be what one thinks it is. > > 2. What would one do with a number (Float or Rational) >   which is arbitrarily close to 1/n but which is not 1/n? > > 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: > > require "complex" > n = -2                #=> -2 > p = 1                 #=> 1 > cn = Complex( n, 0 )  #=> Complex(-2, 0) > cp = Complex( p, 0 )  #=> Complex(1, 0) > n > p                 #=> false > cn > p                #=> true > cn > cp               #=> true > > 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. > > If you're messing around with complex variables and you come across the '>' operator, what else would you expect it to do other than compare absolute values? There's no room for confusion here, it's just a syntax shortcut like we have in so many other places in Ruby. -- Paul Smith http://www.nomadicfun.co.uk paul@pollyandpaul.co.uk