Bug in ruby complex module:

T

Tommy Nordgren

Transcript :
emac$ irbWork 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,274
Messages
2,571,370
Members
48,062
Latest member
leehaan

Latest Threads

Top