# Bug in ruby complex module:

**URL:** <https://www.ruby-forum.com/t/bug-in-ruby-complex-module/124520>\
**Category:** Ruby\
**Created:** [December 29, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/bug-in-ruby-complex-module/124520 "2007-12-29T18:19:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fantomknight10](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/94ad74/32.png) [@fantomknight10](https://www.ruby-forum.com/u/fantomknight10)\
**Post date:** [December 29, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/bug-in-ruby-complex-module/124520/1 "2007-12-29T18:19:30Z")

</div>

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
