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.

208 lines
4.5 KiB

  1. //-----------------------------------------------------------------------------
  2. // Package Title ratpak
  3. // File transh.c
  4. // Author Timothy David Corrie Jr. ([email protected])
  5. // Copyright (C) 1995-96 Microsoft
  6. // Date 01-16-95
  7. //
  8. //
  9. // Description
  10. //
  11. // Contains hyperbolic sin, cos, and tan for rationals.
  12. //
  13. //
  14. //-----------------------------------------------------------------------------
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #if defined( DOS )
  19. #include <dosstub.h>
  20. #else
  21. #include <windows.h>
  22. #endif
  23. #include <ratpak.h>
  24. //-----------------------------------------------------------------------------
  25. //
  26. // FUNCTION: sinhrat, _sinhrat
  27. //
  28. // ARGUMENTS: x PRAT representation of number to take the sine hyperbolic
  29. // of
  30. // RETURN: sinh of x in PRAT form.
  31. //
  32. // EXPLANATION: This uses Taylor series
  33. //
  34. // n
  35. // ___ 2j+1
  36. // \ ] X
  37. // \ ---------
  38. // / (2j+1)!
  39. // /__]
  40. // j=0
  41. // or,
  42. // n
  43. // ___ 2
  44. // \ ] X
  45. // \ thisterm ; where thisterm = thisterm * ---------
  46. // / j j+1 j (2j)*(2j+1)
  47. // /__]
  48. // j=0
  49. //
  50. // thisterm = X ; and stop when thisterm < precision used.
  51. // 0 n
  52. //
  53. // if x is bigger than 1.0 (e^x-e^-x)/2 is used.
  54. //
  55. //-----------------------------------------------------------------------------
  56. void _sinhrat( PRAT *px )
  57. {
  58. CREATETAYLOR();
  59. DUPRAT(pret,*px);
  60. DUPRAT(thisterm,pret);
  61. DUPNUM(n2,num_one);
  62. do {
  63. NEXTTERM(xx,INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2));
  64. } while ( !SMALL_ENOUGH_RAT( thisterm ) );
  65. DESTROYTAYLOR();
  66. }
  67. void sinhrat( PRAT *px )
  68. {
  69. PRAT pret=NULL;
  70. PRAT tmpx=NULL;
  71. if ( rat_ge( *px, rat_one ) )
  72. {
  73. DUPRAT(tmpx,*px);
  74. exprat(px);
  75. tmpx->pp->sign *= -1;
  76. exprat(&tmpx);
  77. subrat( px, tmpx );
  78. divrat( px, rat_two );
  79. destroyrat( tmpx );
  80. }
  81. else
  82. {
  83. _sinhrat( px );
  84. }
  85. }
  86. //-----------------------------------------------------------------------------
  87. //
  88. // FUNCTION: coshrat
  89. //
  90. // ARGUMENTS: x PRAT representation of number to take the cosine
  91. // hyperbolic of
  92. //
  93. // RETURN: cosh of x in PRAT form.
  94. //
  95. // EXPLANATION: This uses Taylor series
  96. //
  97. // n
  98. // ___ 2j
  99. // \ ] X
  100. // \ ---------
  101. // / (2j)!
  102. // /__]
  103. // j=0
  104. // or,
  105. // n
  106. // ___ 2
  107. // \ ] X
  108. // \ thisterm ; where thisterm = thisterm * ---------
  109. // / j j+1 j (2j)*(2j+1)
  110. // /__]
  111. // j=0
  112. //
  113. // thisterm = 1 ; and stop when thisterm < precision used.
  114. // 0 n
  115. //
  116. // if x is bigger than 1.0 (e^x+e^-x)/2 is used.
  117. //
  118. //-----------------------------------------------------------------------------
  119. void _coshrat( PRAT *px )
  120. {
  121. CREATETAYLOR();
  122. pret->pp=longtonum( 1L, nRadix );
  123. pret->pq=longtonum( 1L, nRadix );
  124. DUPRAT(thisterm,pret)
  125. n2=longtonum(0L, nRadix);
  126. do {
  127. NEXTTERM(xx,INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2));
  128. } while ( !SMALL_ENOUGH_RAT( thisterm ) );
  129. DESTROYTAYLOR();
  130. }
  131. void coshrat( PRAT *px )
  132. {
  133. PRAT tmpx=NULL;
  134. (*px)->pp->sign = 1;
  135. (*px)->pq->sign = 1;
  136. if ( rat_ge( *px, rat_one ) )
  137. {
  138. DUPRAT(tmpx,*px);
  139. exprat(px);
  140. tmpx->pp->sign *= -1;
  141. exprat(&tmpx);
  142. addrat( px, tmpx );
  143. divrat( px, rat_two );
  144. destroyrat( tmpx );
  145. }
  146. else
  147. {
  148. _coshrat( px );
  149. }
  150. // Since *px might be epsilon below 1 due to TRIMIT
  151. // we need this trick here.
  152. if ( rat_lt(*px,rat_one) )
  153. {
  154. DUPRAT(*px,rat_one);
  155. }
  156. }
  157. //-----------------------------------------------------------------------------
  158. //
  159. // FUNCTION: tanhrat
  160. //
  161. // ARGUMENTS: x PRAT representation of number to take the tangent
  162. // hyperbolic of
  163. //
  164. // RETURN: tanh of x in PRAT form.
  165. //
  166. // EXPLANATION: This uses sinhrat and coshrat
  167. //
  168. //-----------------------------------------------------------------------------
  169. void tanhrat( PRAT *px )
  170. {
  171. PRAT ptmp=NULL;
  172. DUPRAT(ptmp,*px);
  173. sinhrat(px);
  174. coshrat(&ptmp);
  175. mulnumx(&((*px)->pp),ptmp->pq);
  176. mulnumx(&((*px)->pq),ptmp->pp);
  177. destroyrat(ptmp);
  178. }