gsl_specfunc__shint.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* specfunc/shint.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  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. /* Author: G. Jungman */
  20. #include "gsl__config.h"
  21. #include "gsl_math.h"
  22. #include "gsl_errno.h"
  23. #include "gsl_sf_expint.h"
  24. #include "gsl_specfunc__error.h"
  25. #include "gsl_specfunc__chebyshev.h"
  26. #include "gsl_specfunc__cheb_eval.c"
  27. /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
  28. /* based on SLATEC shi.f, W. Fullerton
  29. series for shi on the interval 0.00000e+00 to 1.40625e-01
  30. with weighted error 4.67e-20
  31. log weighted error 19.33
  32. significant figures required 17.07
  33. decimal places required 19.75
  34. */
  35. static double shi_data[7] = {
  36. 0.0078372685688900950695,
  37. 0.0039227664934234563973,
  38. 0.0000041346787887617267,
  39. 0.0000000024707480372883,
  40. 0.0000000000009379295591,
  41. 0.0000000000000002451817,
  42. 0.0000000000000000000467
  43. };
  44. static cheb_series shi_cs = {
  45. shi_data,
  46. 6,
  47. -1, 1,
  48. 6
  49. };
  50. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  51. int gsl_sf_Shi_e(const double x, gsl_sf_result * result)
  52. {
  53. const double xsml = GSL_SQRT_DBL_EPSILON; /* sqrt (r1mach(3)) */
  54. const double ax = fabs(x);
  55. if(ax < xsml) {
  56. result->val = x;
  57. result->err = 0.0;
  58. return GSL_SUCCESS;
  59. }
  60. else if(ax <= 0.375) {
  61. gsl_sf_result result_c;
  62. cheb_eval_e(&shi_cs, 128.0*x*x/9.0-1.0, &result_c);
  63. result->val = x * (1.0 + result_c.val);
  64. result->err = x * result_c.err;
  65. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  66. return GSL_SUCCESS;
  67. }
  68. else {
  69. gsl_sf_result result_Ei;
  70. gsl_sf_result result_E1;
  71. int status_Ei = gsl_sf_expint_Ei_e(x, &result_Ei);
  72. int status_E1 = gsl_sf_expint_E1_e(x, &result_E1);
  73. result->val = 0.5*(result_Ei.val + result_E1.val);
  74. result->err = 0.5*(result_Ei.err + result_E1.err);
  75. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  76. if(status_Ei == GSL_EUNDRFLW && status_E1 == GSL_EUNDRFLW) {
  77. GSL_ERROR ("underflow", GSL_EUNDRFLW);
  78. }
  79. else if(status_Ei == GSL_EOVRFLW || status_E1 == GSL_EOVRFLW) {
  80. GSL_ERROR ("overflow", GSL_EOVRFLW);
  81. }
  82. else {
  83. return GSL_SUCCESS;
  84. }
  85. }
  86. }
  87. int gsl_sf_Chi_e(const double x, gsl_sf_result * result)
  88. {
  89. gsl_sf_result result_Ei;
  90. gsl_sf_result result_E1;
  91. int status_Ei = gsl_sf_expint_Ei_e(x, &result_Ei);
  92. int status_E1 = gsl_sf_expint_E1_e(x, &result_E1);
  93. if(status_Ei == GSL_EDOM || status_E1 == GSL_EDOM) {
  94. DOMAIN_ERROR(result);
  95. }
  96. else if(status_Ei == GSL_EUNDRFLW && status_E1 == GSL_EUNDRFLW) {
  97. UNDERFLOW_ERROR(result);
  98. }
  99. else if(status_Ei == GSL_EOVRFLW || status_E1 == GSL_EOVRFLW) {
  100. OVERFLOW_ERROR(result);
  101. }
  102. else {
  103. result->val = 0.5 * (result_Ei.val - result_E1.val);
  104. result->err = 0.5 * (result_Ei.err + result_E1.err);
  105. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  106. return GSL_SUCCESS;
  107. }
  108. }
  109. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  110. #include "gsl_specfunc__eval.h"
  111. double gsl_sf_Shi(const double x)
  112. {
  113. EVAL_RESULT(gsl_sf_Shi_e(x, &result));
  114. }
  115. double gsl_sf_Chi(const double x)
  116. {
  117. EVAL_RESULT(gsl_sf_Chi_e(x, &result));
  118. }