Bug #1708
closedrequire 'complex' Causes Unexpected Behaviour
Description
=begin
1.9 has Complex in core, yet on 1.8 you had to explicitly require it with "require 'complex'". However, 1.9 also has a 'complex.rb' in its lib directory which in turn requires 'cmath.rb'. 'cmath.rb' redefines quite a few Math methods. This is particularly confusing because you would expect "require 'complex'" to be a no-op on 1.9, whereas it actually causes Math methods to fail in mysterious ways.
For example, where Math used to raise TypeErrors it now raises NoMethodErrors. This happens for all of the overridden methods.
>> Math.atan(nil)
TypeError: can't convert nil into Float
from (irb):1:in `atan'
from (irb):1
from /usr/local/bin/irb:12:in `<main>'
>> require 'complex'
=> true
>> Math.atan(nil)
NoMethodError: undefined method `real?' for nil:NilClass
from /usr/local/lib/ruby/1.9.1/cmath.rb:145:in `atan'
from (irb):3
from /usr/local/bin/irb:12:in `<main>'
As Complex is in core Math methods should work with complex numbers by default. This half-in-, half-out-, approach is confusing. If the current behavior is intentional, it needs to be clarified in the Math and Complex documentation.
=end