Leaked source code of windows server 2003
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.

159 lines
5.7 KiB

  1. /**************************************************************************\
  2. * *
  3. * *
  4. * *
  5. * # # ##### *
  6. * # # # # # *
  7. * # # # # # # # *
  8. * # ### ### # # *
  9. * # # ### # # # ### # # ### ##### # ### ### ### *
  10. * # ## # # # ## # # # # # # ## # # # *
  11. * # # # # # # # # # ##### # # ##### # *
  12. * # # # # # # # # # # # # # # ## *
  13. * # # # # # # # # # ### # # ### ### ## *
  14. * *
  15. * *
  16. * Infinte Precision Production Version *
  17. * *
  18. \**************************************************************************/
  19. //
  20. // RETAIL version of NUMOBJ math that uses Infinite Precision
  21. //
  22. #include "..\ratpak\ratpak.h"
  23. #define HNUMOBJ PRAT
  24. typedef HNUMOBJ * PHNUMOBJ;
  25. //
  26. // Memory Alloc functions
  27. //
  28. #define NumObjAllocMem( cb ) zmalloc( cb )
  29. #define NumObjFreeMem( h ) zfree( h ),(h=NULL)
  30. //
  31. // Unary functions
  32. //
  33. void NumObjInvert( PHNUMOBJ phno );
  34. #define NumObjNegate( phno ) ( ((PRAT)*phno)->pp->sign= -(((PRAT)*phno)->pp->sign) )
  35. #define NumObjAbs( phno ) ( ((PRAT)*phno)->pp->sign=1, ((PRAT)*phno)->pq->sign=1 )
  36. extern void NumObjSin( PHNUMOBJ phno );
  37. extern void NumObjCos( PHNUMOBJ phno );
  38. extern void NumObjTan( PHNUMOBJ phno );
  39. extern void NumObjAntiLog10( PHNUMOBJ phno );
  40. extern void NumObjNot( PHNUMOBJ phno );
  41. //
  42. // Comparison functions
  43. //
  44. #define NumObjIsZero( hno ) zerrat( hno )
  45. #define NumObjIsLess( hno1, hno2 ) rat_lt( hno1, hno2 )
  46. #define NumObjIsLessEq( hno1, hno2 ) rat_le( hno1, hno2 )
  47. #define NumObjIsGreaterEq( hno1, hno2 ) rat_ge( hno1, hno2 )
  48. #define NumObjIsEq( hno1, hno2 ) rat_equ(hno1, hno2 )
  49. //
  50. // Assignment operator. ('=' in C language)
  51. //
  52. #define NumObjAssign( phnol, hnor ) if (1) { DUPRAT( (*phnol), hnor ); } else
  53. //
  54. // Data type conversion functions
  55. //
  56. void NumObjSetIntValue( PHNUMOBJ phnol, LONG i );
  57. //
  58. // NumObjMakeNumber
  59. //
  60. // HNUMOBJ NumObjMakeNumber( LPTSTR psz );
  61. //
  62. // Converts psz to a number and returns it. Call NumObjDestroy()
  63. // when you are done using the returned NumObj.
  64. //
  65. #define NumObjMakeNumber( fMantNeg, pszMant, fExpNeg, pszExp ) inrat( fMantNeg, pszMant, fExpNeg, pszExp )
  66. //
  67. // NumObjGetSzValue
  68. //
  69. // void NumObjGetSzValue( LPTSTR *ppszNum, int* pcchNum, HNUMOBJ hnoNum, INT nRadix, NUMOBJ_FMT gafmt );
  70. //
  71. // Converts hnoNum to a string and places the pointer into *ppszNum. If *ppszNum already points
  72. // to a string, then that string is freed.
  73. //
  74. // NOTES: *ppszNum must either be NULL or point to a string previously returned by this function!
  75. // If you wish to free the string without replacing it. You MUST use the NumObjFreeMem() function!
  76. //
  77. void NumObjGetSzValue( LPTSTR *ppszNum, int* pcchNum, HNUMOBJ hnoNum, INT nRadix, NUMOBJ_FMT gafmt );
  78. //
  79. // GetObjGetExp
  80. //
  81. // returns an int that equals the exponent of the NumObj
  82. //
  83. #define NumObjGetExp( hno ) LOGRATRADIX(hno)
  84. //
  85. // NumObjCvtEpsilonToZero
  86. //
  87. // if the input is < 1*10^(-nPrecision), then it gets set to zero
  88. // useful for special cases in ln, log, and sin, and cos
  89. //
  90. #define NumObjCvtEpsilonToZero( phno )
  91. //#define NumObjCvtEpsilonToZero( phno ) if ( NumObjGetExp( *phno ) <= -nPrecision ) { NumObjAssign( phno, HNO_ZERO );} else
  92. //
  93. // NumObjAbortOperation( fAbort )
  94. //
  95. // If called with fAbort==TRUE, it will cause RATPAK to abort the current calculation and to return
  96. // immeadiatly.
  97. //
  98. // It MUST be called again with fAbort=FALSE after ratpak has aborted to reset ratpak.
  99. //
  100. #define NumObjAbortOperation( fAbort ) (fhalt=fAbort)
  101. #define NumObjWasAborted() (fhalt)
  102. //
  103. // NumObjOK( hno )
  104. //
  105. // returns TRUE if the HNUMOBJ is valid (ie created and initialized)
  106. //
  107. // Used to check the HNUMOBJ returned from NumObjMakeNumber and NumObjCreate
  108. //
  109. # define NumObjOK( hno ) ((hno) == NULL ? FALSE : TRUE)
  110. //
  111. // NumObjDestroy( hno )
  112. //
  113. // call this when you nolonger need the NumObj. Failure to do so
  114. // will result in memory leaks.
  115. //
  116. # define NumObjDestroy( phno ) destroyrat( (*(phno)) )
  117. //
  118. // DECLARE_HNUMOBJ( hno )
  119. //
  120. // Use this macro when ever you want to declare a local variable.
  121. //
  122. # define DECLARE_HNUMOBJ( hno ) HNUMOBJ hno = NULL
  123. //
  124. // Useful Constants. These have to be recomputed after a base or precision change.
  125. //
  126. void BaseOrPrecisionChanged( void );
  127. #define HNO_ZERO rat_zero
  128. #define HNO_ONE_OVER_TWO rat_half
  129. #define HNO_ONE rat_one
  130. #define HNO_TWO rat_two
  131. #define HNO_180_OVER_PI rad_to_deg
  132. #define HNO_200_OVER_PI rad_to_grad
  133. #define HNO_2PI two_pi
  134. #define HNO_PI pi
  135. #define HNO_PI_OVER_TWO pi_over_two
  136. #define HNO_THREE_PI_OVER_TWO one_pt_five_pi