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.

130 lines
4.3 KiB

  1. /**************************************************************************/
  2. /*** SCICALC Scientific Calculator for Windows 3.00.12 ***/
  3. /*** By Kraig Brockschmidt, Microsoft Co-op, Contractor, 1988-1989 ***/
  4. /*** (c)1989 Microsoft Corporation. All Rights Reserved. ***/
  5. /*** ***/
  6. /*** scioper.c ***/
  7. /*** ***/
  8. /*** Functions contained: ***/
  9. /*** DoOperation--Does common operations. ***/
  10. /*** ***/
  11. /*** Functions called: ***/
  12. /*** DisplayError ***/
  13. /*** ***/
  14. /*** Last modification Thu 31-Aug-1989 ***/
  15. /**************************************************************************/
  16. #include "scicalc.h"
  17. extern BOOL bInv;
  18. extern LONG nPrecision;
  19. /****************************************************************************\
  20. * HNUMOBJ NEAR DoOperation (short nOperation, HNUMOBJ fpx)
  21. *
  22. * Routines to perform standard operations &|^~<<>>+-/*% and pwr.
  23. *
  24. \****************************************************************************/
  25. void DoOperation (INT nOperation, HNUMOBJ *phnoNum, HNUMOBJ hnoX)
  26. {
  27. // NOTE: volatile is used here because of a compiler bug! vc 5 AND 6. This has no effect on the funcationality.
  28. volatile PRAT hno = NULL;
  29. try
  30. {
  31. switch (nOperation)
  32. {
  33. /* Buncha ops. Hope *this* doesn't confuse anyone <smirk>. */
  34. case IDC_AND:
  35. andrat( phnoNum, hnoX );
  36. return;
  37. case IDC_OR:
  38. orrat( phnoNum, hnoX );
  39. return;
  40. case IDC_XOR:
  41. xorrat( phnoNum, hnoX );
  42. return;
  43. case RSHF:
  44. NumObjAssign( &hno, *phnoNum );
  45. NumObjAssign( phnoNum, hnoX );
  46. rshrat( phnoNum, hno );
  47. break;
  48. case IDC_LSHF:
  49. NumObjAssign( &hno, *phnoNum );
  50. NumObjAssign( phnoNum, hnoX );
  51. lshrat( phnoNum, hno );
  52. break;
  53. case IDC_ADD:
  54. addrat( phnoNum, hnoX );
  55. return;
  56. case IDC_SUB:
  57. // in order to do ( hnoX - phnoNum ) we actually do -(phnoNum - hnoX ) cause it's quicker
  58. subrat( phnoNum, hnoX );
  59. NumObjNegate( phnoNum );
  60. return;
  61. case IDC_MUL:
  62. mulrat( phnoNum, hnoX );
  63. return;
  64. case IDC_DIV:
  65. case IDC_MOD:
  66. {
  67. // REVIEW: These lengthly number assignments can be replaced with some quick pointer swaps.
  68. // the swaps cannot change the value of hnoX unless we also modify the code that calls
  69. // the DoOperation function.
  70. NumObjAssign( &hno, *phnoNum );
  71. NumObjAssign( phnoNum, hnoX );
  72. if (nOperation==IDC_DIV) {
  73. divrat(phnoNum, hno ); /* Do division. */
  74. } else {
  75. modrat( phnoNum, hno );
  76. }
  77. break;
  78. }
  79. case IDC_PWR: /* Calculates hnoX to the hnoNum(th) power or root. */
  80. {
  81. NumObjAssign( &hno, *phnoNum );
  82. NumObjAssign( phnoNum, hnoX );
  83. if (bInv) /* Switch for hnoNum(th) root. Null root illegal. */
  84. {
  85. SetBox (IDC_INV, bInv=FALSE);
  86. rootrat( phnoNum, hno); /* Root. */
  87. }
  88. else
  89. {
  90. powrat( phnoNum, hno ); /* Power. */
  91. }
  92. break;
  93. }
  94. }
  95. if ( hno != NULL )
  96. NumObjDestroy( &hno );
  97. }
  98. catch ( DWORD dwErrCode )
  99. {
  100. // if ratpak throws an error, we may need to free the memory used by hno
  101. if ( hno != NULL )
  102. NumObjDestroy( &hno );
  103. DisplayError( dwErrCode );
  104. }
  105. return;
  106. }