From: Marc-Andre Lafortune Date: 2009-11-01T12:54:45+09:00 Subject: [ruby-core:26465] [Bug #2189] Math.atanh(1) & Math.atanh(-1) should not raise an error Issue #2189 has been updated by Marc-Andre Lafortune. File pole.diff added Assigned to set to Yukihiro Matsumoto Hi, I looked at SUSv3 a bit more carefully. I'll refer interested parties to http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap04.html#tag_04_18_02 Yui NARUSE wrote: > So we follow SUSv3, which defines atanh(x) as "If x is ��1, a pole error shall occur, (...)" > And make atanh raise Errno::EDOM or Errno::ERANGE. This appears to be inexact, as Ruby does not follow SUSv3 faithfully. First, SUSv3 clearly distinguishes between what it calls "domain errors", "range errors" and "pole errors". Pole errors are distinct errors and are neither a "domain error" nor a "range error". Returning "Errno::EDOM: Numerical argument out of domain" in a "pole error" situation is in contradiction of SUSv3. Second, Ruby is not even consistent with SUSv3 about "pole errors". SUSv3 states that pole errors occurs in the following cases: Math.log(0.0) Math.atanh(1.0) Math.gamma(0.0) 0.0**(-n) besel functions (no ruby equivalent) Ruby raises the (wrong) exception in the first two cases only, but treatment should be the same according to SUSv3. Ok, so what do we do? SUSv3 provides a mechanism to handle "domain errors", "range errors" and "pole errors", and this mechanism is independent per type of error. Ruby doesn't provide a way to handle these cases. Either Ruby makes valid choices on how to handle these types of errors, or else it should implement a new mechanism to handle these situations. A mechanism could be implemented with a thread local option, say Math.raise_on_pole = true/false, or even hook, say for example: Math.on_pole=lambda{|object, operator, arguments, result| ... } I am not convinced this is really necessary, since valid choices can be made. Range errors and Domain errors occur in situations where no mathematically valid result can be given. The only reasonable options are to either return NaN or raise an error. So raising an error is quite reasonable, in particular since NaN is very rarely useful. Quote from SUSv3: A "pole error" occurs if the mathematical result of the function is an exact infinity (for example, log(0.0)). Since it is possible to return this "exact mathematical result", I strongly believe that Ruby should return the right Infinity. I'm attaching a patch that brings all pole errors in line and returning the right values on all platforms. Is there any opposition to this patch? ---------------------------------------- http://redmine.ruby-lang.org/issues/show/2189 ---------------------------------------- http://redmine.ruby-lang.org