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.

93 lines
2.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // calc.c - calc functions
  24. ////
  25. #include "winlocal.h"
  26. #include <stdlib.h>
  27. #include "calc.h"
  28. ////
  29. // private definitions
  30. ////
  31. ////
  32. // public functions
  33. ////
  34. // MulDivU32 -
  35. // <dwMult1>
  36. // <dwMult2>
  37. // <dwDiv>
  38. //
  39. DWORD DLLEXPORT WINAPI MulDivU32(DWORD dwMult1, DWORD dwMult2, DWORD dwDiv)
  40. {
  41. DWORD dwResult;
  42. if (dwDiv == 0L)
  43. dwResult = ~((DWORD) 0);
  44. else
  45. {
  46. DWORD dwMult3 = 1L;
  47. // make sure calculation does not overflow
  48. //
  49. while (dwMult2 > 0 && dwMult1 >= ~((DWORD) 0) / dwMult2)
  50. {
  51. dwMult2 /= 10L;
  52. dwMult3 *= 10L;
  53. }
  54. // calculation
  55. //
  56. dwResult = dwMult1 * dwMult2 / dwDiv * dwMult3;
  57. }
  58. return dwResult;
  59. }
  60. // GreatestCommonDenominator -
  61. // <a>
  62. // <b>
  63. //
  64. long DLLEXPORT WINAPI GreatestCommonDenominator(long a, long b)
  65. {
  66. if (b == 0)
  67. return a;
  68. else
  69. return GreatestCommonDenominator(b, a % b);
  70. }
  71. // LeastCommonMultiple -
  72. // <a>
  73. // <b>
  74. //
  75. long DLLEXPORT WINAPI LeastCommonMultiple(long a, long b)
  76. {
  77. return (a * b) / GreatestCommonDenominator(a, b);
  78. }