# Fw: Bug in ruby complex module

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

e\$B8+Mn\$H\$7\$F\$^\$7\$?\$,!":rG/Kv\$K!Ve(BComplexe\$B\$N=|;;\$K%P%0\$,\$"\$k!W\$He(B
e\$B\$\$\$&%a!<%k\$,e(Bruby-coree\$B\$KMh\$F\$^\$7\$?!#e(B[ruby-talk:285292]

e\$B8=>u\$Ne(BCe\$BAH\$9~\$\$Ne(Bcomplexe\$B\$G\$bF1MM\$N!VLdBj!W\$,\$"\$j\$^\$9!#\$?\$@!"e(B
e\$B;d\$K\$O\$3\$l\$,K\Ev\$KLdBj\$J\$N\$+\$I\$&\$+H=CG\$G\$-\$^\$;\$s\$N\$G!"0U8+\$re(B
e\$BD0\$+\$;\$F\$/\$@\$5\$\$!#e(B

Date: Sun, 30 Dec 2007 02:18:36 +0900
Posted: Sat, 29 Dec 2007 18:18:38 +0100
From: Tommy N.

Transcript :
emac\$ irb

require ‘complex’
=> true

cc = Complex(Float::MAX/2, Float::MAX / 2)
=> Complex(8.98846567431158e+307, 8.98846567431158e+307)

cc / cc
=> Complex(NaN, NaN)

require ‘cpfixup’
=> true

cc / cc
=> Complex(1.0, 0.0)

exit
Work Directory: ~ :
emac\$
Th source of the fix (in a file called ‘cpfixup.rb’ in my home
directory is

require ‘complex’

class Complex < Numeric

def / (other)
if other.kind_of?(Complex)
magn = other.abs
tmp = Complex.new(other.real/magn , other.image/magn)
self * tmp.conjugate / magn
elsif Complex.generic?(other)
Complex(@real/other, @image/other)
else
x, y = other.coerce(self)
x / y
end
end
end

|From: Yukihiro M. [email protected]

e\$B8+Mn\$H\$7\$F\$^\$7\$?\$,!“:rG/Kv\$K!Ve(BComplexe\$B\$N=|;;\$K%P%0\$,\$”\$k!W\$He(B
e\$B\$\$\$&%a!<%k\$,e(Bruby-coree\$B\$KMh\$F\$^\$7\$?!#e(B[ruby-talk:285292]

e\$B8=>u\$Ne(BCe\$BAH\$9~\$\$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$H\$7\$F\$^\$7\$?\$,!“:rG/Kv\$K!Ve(BComplexe\$B\$N=|;;\$K%P%0\$,\$”\$k!W\$He(B
e\$B\$\$\$&%a!<%k\$,e(Bruby-coree\$B\$KMh\$F\$^\$7\$?!#e(B[ruby-talk:285292]

e\$B8=>u\$Ne(BCe\$BAH\$9~\$\$Ne(Bcomplexe\$B\$G\$bF1MM\$N!VLdBj!W\$,\$"\$j\$^\$9!#\$?\$@!"e(B
e\$B;d\$K\$O\$3\$l\$,K\Ev\$KLdBj\$J\$N\$+\$I\$&\$+H=CG\$G\$-\$^\$;\$s\$N\$G!"0U8+\$re(B
e\$BD0\$+\$;\$F\$/\$@\$5\$\$!#e(B

e\$B@dBPCM\$,Bg\$-\$JIbF0>.?tE@?t\$N>h;;\$GJ,Jl\$,e(B INF
e\$B\$K\$J\$j!\$\$=\$N1F6A\$Ge(B
e\$B7k2L\$,e(B NaN e\$B\$K\$J\$C\$F\$\$\$k\$b\$N\$H;W\$o\$l\$^\$9!%;d\$Ne(B ComplexFloat
e\$B\$G\$Oe(B
C99 Draft e\$B\$K:\$C\$F\$\$\$?3d\$j;;\$N<BAue(B (log
e\$B\$G%9%1!<%j%s%0\$9\$kJ}K!e(B) e\$B\$re(B
e\$B;H\$C\$F\$\$\$k\$N\$G!\$\$3\$N\$h\$&\$JLdBj\$O5/\$3\$j\$^\$;\$s!%e(Bcomplex.c e\$B\$G\$be(B
[email protected],\$,e(B Float e\$B\$N;~\$OF1MM\$NBP1~\$r\$9\$kI,MW\$,\$"\$k\$H;W\$\$\$^\$9!%e(B

muraken:~/src/ruby\$ ./miniruby -e ‘cc = ComplexFloat(Float::MAX/2,
Float::MAX/2); p cc/cc’
ComplexFloat(1.0, 0.0)