asinhf.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* asinhf.c
  2. *
  3. * Inverse hyperbolic sine
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, y, asinhf();
  10. *
  11. * y = asinhf( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns inverse hyperbolic sine of argument.
  18. *
  19. * If |x| < 0.5, the function is approximated by a rational
  20. * form x + x**3 P(x)/Q(x). Otherwise,
  21. *
  22. * asinh(x) = log( x + sqrt(1 + x*x) ).
  23. *
  24. *
  25. *
  26. * ACCURACY:
  27. *
  28. * Relative error:
  29. * arithmetic domain # trials peak rms
  30. * IEEE -3,3 100000 2.4e-7 4.1e-8
  31. *
  32. */
  33. /* asinh.c */
  34. /*
  35. Cephes Math Library Release 2.2: June, 1992
  36. Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
  37. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  38. */
  39. /* Single precision inverse hyperbolic sine
  40. * test interval: [-0.5, +0.5]
  41. * trials: 10000
  42. * peak relative error: 8.8e-8
  43. * rms relative error: 3.2e-8
  44. */
  45. #include <math.h>
  46. extern float LOGE2F;
  47. float logf( float );
  48. float sqrtf( float );
  49. float asinhf( float xx )
  50. {
  51. float x, z;
  52. if( xx < 0 )
  53. x = -xx;
  54. else
  55. x = xx;
  56. if( x > 1500.0 )
  57. {
  58. z = logf(x) + LOGE2F;
  59. goto done;
  60. }
  61. z = x * x;
  62. if( x < 0.5 )
  63. {
  64. z =
  65. ((( 2.0122003309E-2 * z
  66. - 4.2699340972E-2) * z
  67. + 7.4847586088E-2) * z
  68. - 1.6666288134E-1) * z * x
  69. + x;
  70. }
  71. else
  72. {
  73. z = sqrtf( z + 1.0 );
  74. z = logf( x + z );
  75. }
  76. done:
  77. if( xx < 0 )
  78. z = -z;
  79. return( z );
  80. }