From: Colin Bartlett Date: 2009-12-21T05:12:46+09:00 Subject: Re: Correcting complex math On Sun, Dec 20, 2009 at 3:15 PM, Robert Klemme wrote: > 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: > 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) Thanks for that! You've embarrassed me into installing Ruby 1.9 for Windows to check one or two other things! And I'm pleased to see that: require "complex" ; p Complex( 7, 0 ) % 3 ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] Complex(1, 0) ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32] in '
': undefined method '%' for (7+0i):Complex (NoMethoError) And whereas in 1.8: require "complex" c7 = Complex( 7, 0 ) #=> Complex(7, 0) c7n = Complex( -7, 0 ) #=> Complex(-7, 0) c7i = Complex( 0, 7 ) #=> Complex(0, 7) c7n <=> c7i #=> 0 c7i <=> c7 #=> 0 c7n <=> c7 #=> 0 require "mathn" c7 = Complex( 7, 0 ) #=> 7 c7n = Complex( -7, 0 ) #=> -7 c7i = Complex( 0, 7 ) #=> Complex(0, 7) c7n <=> c7i #=> 0 c7i <=> c7 #=> 0 c7n <=> c7 #=> -1 In 1.9 the "<=>" is not (as you pointed out) defined, so we get the (from my point of view) desirable "collapse" of the program, instead of the (from my point of view) inconsistent results of 1.8. This post from July 2009 seems relevant: http://redmine.ruby-lang.org/issues/show/1712 ... writes > |1.8's Complex had a modulus operator (%); 1.9's doesn't, and attempts to use it > raise a NoMethodError for #floor because it falls back to Numeric#% > which needs #floor. Is this omission intentional? If so, > could an appropriate NoMethodError be raised instead? > If not, I'd appreciate knowing so I can write the specifications. I don't think there's natural definition of modulo on complex numbers, so that we should undefine % method. We might need to do something for compatibility's sake. Opinion? matz. Does anyone know of any other threads on this? *** OffTopic *** > remember.guy do |as, often| as.you_can - without end I doubt if I understood 5% (if that) of the technical parts of Guy Decoux's posts. Which is to say, given his terse style, almost every part of his posts. But even I could detect a rather endearing underlying humour in those posts.