gsl_specfunc__clausen.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* specfunc/clausen.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_trig.h"
  24. #include "gsl_sf_clausen.h"
  25. #include "gsl_specfunc__chebyshev.h"
  26. #include "gsl_specfunc__cheb_eval.c"
  27. static double aclaus_data[15] = {
  28. 2.142694363766688447e+00,
  29. 0.723324281221257925e-01,
  30. 0.101642475021151164e-02,
  31. 0.3245250328531645e-04,
  32. 0.133315187571472e-05,
  33. 0.6213240591653e-07,
  34. 0.313004135337e-08,
  35. 0.16635723056e-09,
  36. 0.919659293e-11,
  37. 0.52400462e-12,
  38. 0.3058040e-13,
  39. 0.18197e-14,
  40. 0.1100e-15,
  41. 0.68e-17,
  42. 0.4e-18
  43. };
  44. static cheb_series aclaus_cs = {
  45. aclaus_data,
  46. 14,
  47. -1, 1,
  48. 8 /* FIXME: this is a guess, correct value needed here BJG */
  49. };
  50. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  51. int gsl_sf_clausen_e(double x, gsl_sf_result *result)
  52. {
  53. const double x_cut = M_PI * GSL_SQRT_DBL_EPSILON;
  54. double sgn = 1.0;
  55. int status_red;
  56. if(x < 0.0) {
  57. x = -x;
  58. sgn = -1.0;
  59. }
  60. /* Argument reduction to [0, 2pi) */
  61. status_red = gsl_sf_angle_restrict_pos_e(&x);
  62. /* Further reduction to [0,pi) */
  63. if(x > M_PI) {
  64. /* simulated extra precision: 2PI = p0 + p1 */
  65. const double p0 = 6.28125;
  66. const double p1 = 0.19353071795864769253e-02;
  67. x = (p0 - x) + p1;
  68. sgn = -sgn;
  69. }
  70. if(x == 0.0) {
  71. result->val = 0.0;
  72. result->err = 0.0;
  73. }
  74. else if(x < x_cut) {
  75. result->val = x * (1.0 - log(x));
  76. result->err = x * GSL_DBL_EPSILON;
  77. }
  78. else {
  79. const double t = 2.0*(x*x / (M_PI*M_PI) - 0.5);
  80. gsl_sf_result result_c;
  81. cheb_eval_e(&aclaus_cs, t, &result_c);
  82. result->val = x * (result_c.val - log(x));
  83. result->err = x * (result_c.err + GSL_DBL_EPSILON);
  84. }
  85. result->val *= sgn;
  86. return status_red;
  87. }
  88. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  89. #include "gsl_specfunc__eval.h"
  90. double gsl_sf_clausen(const double x)
  91. {
  92. EVAL_RESULT(gsl_sf_clausen_e(x, &result));
  93. }