Project

General

Profile

Bug #2754

Inconsistent behavior of Math methods on 1.8 when requiring Complex library

Added by brixen (Brian Shirai) over 9 years ago. Updated about 8 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin9.8.0]
[ruby-core:28201]

Description

=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


Related issues

Related to Ruby trunk - Bug #2756: Issues with Math and Complex behavior on 1.9RejectedActions

Also available in: Atom PDF