Skip to content

bug in acosh (win32) (PR#9403)

2 messages · Brian Ripley, Tom Short

#
This is a bug in the mingw runtime, and not in R.  So the difference is 
between OSes, not between R versions.  Note that
[1] 1.316958
[1] 0+NaNi
[1] 1.316958+0i

so it seems to be happening only for exactly real complex numbers.
I think there are also problems with branch cuts.
On Thu, 30 Nov 2006, tshort at eprisolutions.com wrote:

            
acosh is unrelated to those.

  
    
#
Interesting. Unfortunately, that's a common scenerio to convert to
complex numbers to ensure complex output if appropriate:
acosh(as.complex(-2))

I guess acosh(as.complex(x) + 1e-10i) is a bit better than my current
workaround of:

myacosh <- function(x) log(x + sqrt(x^2 - 1))
According to this:
http://mingw.cvs.sourceforge.net/mingw/runtime/mingwex/complex/cacosh.c?view=markup
cacosh uses either casin or cacos, so it looks like they are
related. And, the ifdef's for z_acos and z_asin both say "broken for
cabs(*z) >= 1", matching this:
[1] 0+0.1415395i
[1] 0+NaNi

That also turned up a similar bug in mingw's asinh, this time with
real and imaginary components swapped:
[1] 0+NaNi
[1] 1.316958+1.570796i

- Tom
Tom Short
EPRI Solutions, Inc.