atanhf.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* atanhf.c
  2. *
  3. * Inverse hyperbolic tangent
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, y, atanhf();
  10. *
  11. * y = atanhf( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns inverse hyperbolic tangent of argument in the range
  18. * MINLOGF to MAXLOGF.
  19. *
  20. * If |x| < 0.5, a polynomial approximation is used.
  21. * Otherwise,
  22. * atanh(x) = 0.5 * log( (1+x)/(1-x) ).
  23. *
  24. *
  25. *
  26. * ACCURACY:
  27. *
  28. * Relative error:
  29. * arithmetic domain # trials peak rms
  30. * IEEE -1,1 100000 1.4e-7 3.1e-8
  31. *
  32. */
  33. /* atanh.c */
  34. /*
  35. Cephes Math Library Release 2.2: June, 1992
  36. Copyright (C) 1987, 1992 by Stephen L. Moshier
  37. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  38. */
  39. /* Single precision inverse hyperbolic tangent
  40. * test interval: [-0.5, +0.5]
  41. * trials: 10000
  42. * peak relative error: 8.2e-8
  43. * rms relative error: 3.0e-8
  44. */
  45. #include <math.h>
  46. extern float MAXNUMF;
  47. float logf( float );
  48. float atanhf( float xx )
  49. {
  50. float x, z;
  51. x = xx;
  52. if( x < 0 )
  53. z = -x;
  54. else
  55. z = x;
  56. if( z >= 1.0 )
  57. {
  58. if( x == 1.0 )
  59. return( MAXNUMF );
  60. if( x == -1.0 )
  61. return( -MAXNUMF );
  62. mtherr( "atanhl", DOMAIN );
  63. return( MAXNUMF );
  64. }
  65. if( z < 1.0e-4 )
  66. return(x);
  67. if( z < 0.5 )
  68. {
  69. z = x * x;
  70. z =
  71. (((( 1.81740078349E-1 * z
  72. + 8.24370301058E-2) * z
  73. + 1.46691431730E-1) * z
  74. + 1.99782164500E-1) * z
  75. + 3.33337300303E-1) * z * x
  76. + x;
  77. }
  78. else
  79. {
  80. z = 0.5 * logf( (1.0+x)/(1.0-x) );
  81. }
  82. return( z );
  83. }