1

I am trying to use asinh function from math module in Ironpython 2.7. Anytime I have a float < -1, I get nan as a result. I know that in cmath they are some branch cuts due to the potential use of complex numbers, but here I work with reals and the documentation explains that math is the appropriate module.

asinh(-.5)
asinh(-1.)
asinh(-1.001)

>>-0.481211
>>-0.881373
>>nan

Am I missing something ? This is working fine with all other flavours of Python I use.

Is it necessary to write a custom function using the log(x+sqrt(x**2+1) definition ? I really wonder what is going on here so I would be very grateful for any thorough answer on this.

Jongware
  • 22,200
  • 8
  • 54
  • 100
Jacques Gaudin
  • 15,779
  • 10
  • 54
  • 75

1 Answers1

1

Looking into the sources, I found this pretty loose implementation :

if (Math.Abs(v0) > 1.0) { 
    return Math.Log(v0) + Math.Log(1.0 + MathUtils.Hypot(1.0, 1.0 / v0));}

That is why ! If v0 < -1, then Abs(v0) > 1 but Math.Log(v0) is not defined... I submitted the issue to the IronPython team on GitHub and suggested using Math.Sign to fix the issue like so :

 if (Math.Abs(v0) > 1.0) { 
     return Math.Sign(v0)*(Math.Log(Math.Abs(v0)) + 
               Math.Log(1.0 + MathUtils.Hypot(1.0, 1.0 / v0)));}
Jacques Gaudin
  • 15,779
  • 10
  • 54
  • 75