ellpkf.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* ellpkf.c
  2. *
  3. * Complete elliptic integral of the first kind
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float m1, y, ellpkf();
  10. *
  11. * y = ellpkf( m1 );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Approximates the integral
  18. *
  19. *
  20. *
  21. * pi/2
  22. * -
  23. * | |
  24. * | dt
  25. * K(m) = | ------------------
  26. * | 2
  27. * | | sqrt( 1 - m sin t )
  28. * -
  29. * 0
  30. *
  31. * where m = 1 - m1, using the approximation
  32. *
  33. * P(x) - log x Q(x).
  34. *
  35. * The argument m1 is used rather than m so that the logarithmic
  36. * singularity at m = 1 will be shifted to the origin; this
  37. * preserves maximum accuracy.
  38. *
  39. * K(0) = pi/2.
  40. *
  41. * ACCURACY:
  42. *
  43. * Relative error:
  44. * arithmetic domain # trials peak rms
  45. * IEEE 0,1 30000 1.3e-7 3.4e-8
  46. *
  47. * ERROR MESSAGES:
  48. *
  49. * message condition value returned
  50. * ellpkf domain x<0, x>1 0.0
  51. *
  52. */
  53. /* ellpk.c */
  54. /*
  55. Cephes Math Library, Release 2.0: April, 1987
  56. Copyright 1984, 1987 by Stephen L. Moshier
  57. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  58. */
  59. #include <math.h>
  60. static float P[] =
  61. {
  62. 1.37982864606273237150E-4,
  63. 2.28025724005875567385E-3,
  64. 7.97404013220415179367E-3,
  65. 9.85821379021226008714E-3,
  66. 6.87489687449949877925E-3,
  67. 6.18901033637687613229E-3,
  68. 8.79078273952743772254E-3,
  69. 1.49380448916805252718E-2,
  70. 3.08851465246711995998E-2,
  71. 9.65735902811690126535E-2,
  72. 1.38629436111989062502E0
  73. };
  74. static float Q[] =
  75. {
  76. 2.94078955048598507511E-5,
  77. 9.14184723865917226571E-4,
  78. 5.94058303753167793257E-3,
  79. 1.54850516649762399335E-2,
  80. 2.39089602715924892727E-2,
  81. 3.01204715227604046988E-2,
  82. 3.73774314173823228969E-2,
  83. 4.88280347570998239232E-2,
  84. 7.03124996963957469739E-2,
  85. 1.24999999999870820058E-1,
  86. 4.99999999999999999821E-1
  87. };
  88. static float C1 = 1.3862943611198906188E0; /* log(4) */
  89. extern float MACHEPF, MAXNUMF;
  90. float polevlf(float, float *, int);
  91. float p1evlf(float, float *, int);
  92. float logf(float);
  93. float ellpkf(float xx)
  94. {
  95. float x;
  96. x = xx;
  97. if( (x < 0.0) || (x > 1.0) )
  98. {
  99. mtherr( "ellpkf", DOMAIN );
  100. return( 0.0 );
  101. }
  102. if( x > MACHEPF )
  103. {
  104. return( polevlf(x,P,10) - logf(x) * polevlf(x,Q,10) );
  105. }
  106. else
  107. {
  108. if( x == 0.0 )
  109. {
  110. mtherr( "ellpkf", SING );
  111. return( MAXNUMF );
  112. }
  113. else
  114. {
  115. return( C1 - 0.5 * logf(x) );
  116. }
  117. }
  118. }