acoshf.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* acoshf.c
  2. *
  3. * Inverse hyperbolic cosine
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, y, acoshf();
  10. *
  11. * y = acoshf( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns inverse hyperbolic cosine of argument.
  18. *
  19. * If 1 <= x < 1.5, a polynomial approximation
  20. *
  21. * sqrt(z) * P(z)
  22. *
  23. * where z = x-1, is used. Otherwise,
  24. *
  25. * acosh(x) = log( x + sqrt( (x-1)(x+1) ).
  26. *
  27. *
  28. *
  29. * ACCURACY:
  30. *
  31. * Relative error:
  32. * arithmetic domain # trials peak rms
  33. * IEEE 1,3 100000 1.8e-7 3.9e-8
  34. * IEEE 1,2000 100000 3.0e-8
  35. *
  36. *
  37. * ERROR MESSAGES:
  38. *
  39. * message condition value returned
  40. * acoshf domain |x| < 1 0.0
  41. *
  42. */
  43. /* acosh.c */
  44. /*
  45. Cephes Math Library Release 2.2: June, 1992
  46. Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
  47. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  48. */
  49. /* Single precision inverse hyperbolic cosine
  50. * test interval: [1.0, 1.5]
  51. * trials: 10000
  52. * peak relative error: 1.7e-7
  53. * rms relative error: 5.0e-8
  54. *
  55. * Copyright (C) 1989 by Stephen L. Moshier. All rights reserved.
  56. */
  57. #include <math.h>
  58. extern float LOGE2F;
  59. float sqrtf( float );
  60. float logf( float );
  61. float acoshf( float xx )
  62. {
  63. float x, z;
  64. x = xx;
  65. if( x < 1.0 )
  66. {
  67. mtherr( "acoshf", DOMAIN );
  68. return(0.0);
  69. }
  70. if( x > 1500.0 )
  71. return( logf(x) + LOGE2F );
  72. z = x - 1.0;
  73. if( z < 0.5 )
  74. {
  75. z =
  76. (((( 1.7596881071E-3 * z
  77. - 7.5272886713E-3) * z
  78. + 2.6454905019E-2) * z
  79. - 1.1784741703E-1) * z
  80. + 1.4142135263E0) * sqrtf( z );
  81. }
  82. else
  83. {
  84. z = sqrtf( z*(x+1.0) );
  85. z = logf(x + z);
  86. }
  87. return( z );
  88. }