Project

General

Profile

Actions

Backport #2754

closed

Inconsistent behavior of Math methods on 1.8 when requiring Complex library

Added by brixen (Brian Shirai) about 14 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
[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 1 (0 open1 closed)

Related to Ruby master - Bug #2756: Issues with Math and Complex behavior on 1.9Rejectedmrkn (Kenta Murata)Actions
Actions #1

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby 1.8 to Backport187
  • Description updated (diff)
  • Status changed from Open to Closed
  • ruby -v deleted (ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin9.8.0])
Actions

Also available in: Atom PDF

Like0
Like0