gsl_sys__invhyp.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* sys/invhyp.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #include "gsl__config.h"
  20. #include <math.h>
  21. #include "gsl_math.h"
  22. #include "gsl_machine.h"
  23. double
  24. gsl_acosh (const double x)
  25. {
  26. if (x > 1.0 / GSL_SQRT_DBL_EPSILON)
  27. {
  28. return log (x) + M_LN2;
  29. }
  30. else if (x > 2)
  31. {
  32. return log (2 * x - 1 / (sqrt (x * x - 1) + x));
  33. }
  34. else if (x > 1)
  35. {
  36. double t = x - 1;
  37. return log1p (t + sqrt (2 * t + t * t));
  38. }
  39. else if (x == 1)
  40. {
  41. return 0;
  42. }
  43. else
  44. {
  45. return GSL_NAN;
  46. }
  47. }
  48. double
  49. gsl_asinh (const double x)
  50. {
  51. double a = fabs (x);
  52. double s = (x < 0) ? -1 : 1;
  53. if (a > 1 / GSL_SQRT_DBL_EPSILON)
  54. {
  55. return s * (log (a) + M_LN2);
  56. }
  57. else if (a > 2)
  58. {
  59. return s * log (2 * a + 1 / (a + sqrt (a * a + 1)));
  60. }
  61. else if (a > GSL_SQRT_DBL_EPSILON)
  62. {
  63. double a2 = a * a;
  64. return s * log1p (a + a2 / (1 + sqrt (1 + a2)));
  65. }
  66. else
  67. {
  68. return x;
  69. }
  70. }
  71. double
  72. gsl_atanh (const double x)
  73. {
  74. double a = fabs (x);
  75. double s = (x < 0) ? -1 : 1;
  76. if (a > 1)
  77. {
  78. return GSL_NAN;
  79. }
  80. else if (a == 1)
  81. {
  82. return (x < 0) ? GSL_NEGINF : GSL_POSINF;
  83. }
  84. else if (a >= 0.5)
  85. {
  86. return s * 0.5 * log1p (2 * a / (1 - a));
  87. }
  88. else if (a > GSL_DBL_EPSILON)
  89. {
  90. return s * 0.5 * log1p (2 * a + 2 * a * a / (1 - a));
  91. }
  92. else
  93. {
  94. return x;
  95. }
  96. }