Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
3.7 KiB

  1. //-----------------------------------------------------------------------------
  2. // Package Title ratpak
  3. // File itransh.c
  4. // Author Timothy David Corrie Jr. ([email protected])
  5. // Copyright (C) 1995-97 Microsoft
  6. // Date 01-16-95
  7. //
  8. //
  9. // Description
  10. //
  11. // Contains inverse hyperbolic sin, cos, and tan functions.
  12. //
  13. // Special Information
  14. //
  15. //
  16. //-----------------------------------------------------------------------------
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #if defined( DOS )
  21. #include <dosstub.h>
  22. #else
  23. #include <windows.h>
  24. #endif
  25. #include <ratpak.h>
  26. //-----------------------------------------------------------------------------
  27. //
  28. // FUNCTION: asinhrat
  29. //
  30. // ARGUMENTS: x PRAT representation of number to take the inverse
  31. // hyperbolic sine of
  32. // RETURN: asinh of x in PRAT form.
  33. //
  34. // EXPLANATION: This uses Taylor series
  35. //
  36. // n
  37. // ___ 2 2
  38. // \ ] -(2j+1) X
  39. // \ thisterm ; where thisterm = thisterm * ---------
  40. // / j j+1 j (2j+2)*(2j+3)
  41. // /__]
  42. // j=0
  43. //
  44. // thisterm = X ; and stop when thisterm < precision used.
  45. // 0 n
  46. //
  47. // For abs(x) < .85, and
  48. //
  49. // asinh(x) = log(x+sqrt(x^2+1))
  50. //
  51. // For abs(x) >= .85
  52. //
  53. //-----------------------------------------------------------------------------
  54. void asinhrat( PRAT *px )
  55. {
  56. PRAT neg_pt_eight_five = NULL;
  57. DUPRAT(neg_pt_eight_five,pt_eight_five);
  58. neg_pt_eight_five->pp->sign *= -1;
  59. if ( rat_gt( *px, pt_eight_five) || rat_lt( *px, neg_pt_eight_five) )
  60. {
  61. PRAT ptmp = NULL;
  62. DUPRAT(ptmp,(*px));
  63. mulrat(&ptmp,*px);
  64. addrat(&ptmp,rat_one);
  65. rootrat(&ptmp,rat_two);
  66. addrat(px,ptmp);
  67. lograt(px);
  68. destroyrat(ptmp);
  69. }
  70. else
  71. {
  72. CREATETAYLOR();
  73. xx->pp->sign *= -1;
  74. DUPRAT(pret,(*px));
  75. DUPRAT(thisterm,(*px));
  76. DUPNUM(n2,num_one);
  77. do
  78. {
  79. NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
  80. INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2));
  81. }
  82. while ( !SMALL_ENOUGH_RAT( thisterm ) );
  83. DESTROYTAYLOR();
  84. }
  85. destroyrat(neg_pt_eight_five);
  86. }
  87. //-----------------------------------------------------------------------------
  88. //
  89. // FUNCTION: acoshrat
  90. //
  91. // ARGUMENTS: x PRAT representation of number to take the inverse
  92. // hyperbolic cose of
  93. // RETURN: acosh of x in PRAT form.
  94. //
  95. // EXPLANATION: This uses
  96. //
  97. // acosh(x)=ln(x+sqrt(x^2-1))
  98. //
  99. // For x >= 1
  100. //
  101. //-----------------------------------------------------------------------------
  102. void acoshrat( PRAT *px )
  103. {
  104. if ( rat_lt( *px, rat_one ) )
  105. {
  106. throw CALC_E_DOMAIN;
  107. }
  108. else
  109. {
  110. PRAT ptmp = NULL;
  111. DUPRAT(ptmp,(*px));
  112. mulrat(&ptmp,*px);
  113. subrat(&ptmp,rat_one);
  114. rootrat(&ptmp,rat_two);
  115. addrat(px,ptmp);
  116. lograt(px);
  117. destroyrat(ptmp);
  118. }
  119. }
  120. //-----------------------------------------------------------------------------
  121. //
  122. // FUNCTION: atanhrat
  123. //
  124. // ARGUMENTS: x PRAT representation of number to take the inverse
  125. // hyperbolic tangent of
  126. //
  127. // RETURN: atanh of x in PRAT form.
  128. //
  129. // EXPLANATION: This uses
  130. //
  131. // 1 x+1
  132. // atanh(x) = -*ln(----)
  133. // 2 x-1
  134. //
  135. //-----------------------------------------------------------------------------
  136. void atanhrat( PRAT *px )
  137. {
  138. PRAT ptmp = NULL;
  139. DUPRAT(ptmp,(*px));
  140. subrat(&ptmp,rat_one);
  141. addrat(px,rat_one);
  142. divrat(px,ptmp);
  143. (*px)->pp->sign *= -1;
  144. lograt(px);
  145. divrat(px,rat_two);
  146. destroyrat(ptmp);
  147. }