Project

General

Profile

Backport #2754

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

=begin 
  
  On 1.8, requiring lib/complex.rb changes the behavior of Math methods to be Complex-aware. However, the new methods do not behave consistently with the methods they are replacing on various aspects not involving Complex numbers. 
 
  Here is an example with Math.atanh: 
 
  # The original method coerces an argument 
  $ ruby1.8.7 -v -e 'o = Object.new; def o.to_f; 0.5; end; p Math.atanh(o)' 
  ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin9.8.0] 
  0.549306144334055 
 
  # The new method does not 
  $ ruby1.8.7 -v -rcomplex -e 'o = Object.new; def o.to_f; 0.5; end; p Math.atanh(o)' 
  ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin9.8.0] 
  /Users/brian/devel/ruby187/install/lib/ruby/1.8/complex.rb:614:in `+': Object can't be coerced into Float (TypeError) 
          from /Users/brian/devel/ruby187/install/lib/ruby/1.8/complex.rb:614:in `atanh' 
          from -e:1 
 
  # The original method raises an ArgumentError 
  $ ruby1.8.7 -v -e 'p Math.atanh("str")'ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin9.8.0] 
  -e:1:in `atanh': invalid value for Float(): "str" (ArgumentError) 
          from -e:1 
 
  # The new method raises a TypeError 
  $ ruby1.8.7 -v -rcomplex -e 'p Math.atanh("str")' 
  ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin9.8.0] 
  /Users/brian/devel/ruby187/install/lib/ruby/1.8/complex.rb:614:in `+': String can't be coerced into Float (TypeError) 
          from /Users/brian/devel/ruby187/install/lib/ruby/1.8/complex.rb:614:in `atanh' 
          from -e:1 
 
  These methods should behave consistently on all inputs that are not Complex. 
 
  There are numerous tickets related to Complex and Math interaction. I was unable to find one that states a satisfactory explanation to this issue. If there is one, please direct me to it and I apologize for the noise. 
 
  Thanks, 
  Brian 
 
 =end 
 

Back