From: Yukihiro Matsumoto Date: 2008-04-12T21:28:15+09:00 Subject: [ruby-dev:34357] fw: Bug in ruby complex module まつもと ゆきひろです 見落としてましたが、昨年末に「Complexの除算にバグがある」と いうメールがruby-coreに来てました。[ruby-talk:285292] 現状のC組み込みのcomplexでも同様の「問題」があります。ただ、 私にはこれが本当に問題なのかどうか判断できませんので、意見を 聴かせてください。 Date: Sun, 30 Dec 2007 02:18:36 +0900 Posted: Sat, 29 Dec 2007 18:18:38 +0100 From: Tommy Nordgren 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 ------------------------------------ This sig is dedicated to the advancement of Nuclear Power Tommy Nordgren