From: Run Paint Run Run Date: 2009-07-01T04:39:40+09:00 Subject: [ruby-core:24099] [Bug #1708] require 'complex' Causes Unexpected Behaviour Bug #1708: require 'complex' Causes Unexpected Behaviour http://redmine.ruby-lang.org/issues/show/1708 Author: Run Paint Run Run Status: Open, Priority: Normal Category: lib ruby -v: ruby 1.9.2dev (2009-06-27 trunk 23871) [i686-linux] 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 `
' >> 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 `
' 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. ---------------------------------------- http://redmine.ruby-lang.org