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.

110 lines
8.3 KiB

  1. /*-----------------------------------------------------------------------------+
  2. | MATH.C |
  3. | |
  4. | Written to provide MulDiv32 for the Win32 version of MPlayer2 |
  5. | |
  6. | Multiplies two 32 bit values and then divides the result by a third |
  7. | 32 bit value with full 64 bit precision |
  8. | N.B. NOT TRUE. However it is good enough for general MPlayer use. |
  9. | |
  10. | lResult = (lNumber * lNumerator) / lDenominator with correct rounding |
  11. | |
  12. | Entry: |
  13. | lNumber = number to multiply by nNumerator |
  14. | lNumerator = number to multiply by nNumber |
  15. | lDenominator = number to divide the multiplication result by. |
  16. | |
  17. | Returns: |
  18. | result of multiplication and division. |
  19. | |
  20. | (This is less accurate than the Win16 ASM version as it cannot be written in |
  21. | ASM (for portability reasons) and NT doesn't yet support 64 bit arithmetic) |
  22. | This file houses the discardable code used at initialisation time. Among |
  23. | other things, this code reads .INI information and looks for MCI devices. |
  24. | |
  25. | |
  26. | NOTE: This code is NOT safe when the intermediate result becomes negative |
  27. | or overflows. However it is simple, quick, and safe for a wide |
  28. | number of uses within MPLayer. |
  29. | |
  30. | (C) Copyright Microsoft Corporation 1991. All rights reserved. |
  31. | |
  32. | Revision History |
  33. | 21-Oct-1992 MikeTri Created by "cloning" MATH.ASM |
  34. | |
  35. +------------------------------------------------------------------------------+
  36. | |
  37. | Original MulDiv32 PseudoCode |
  38. | ============================ |
  39. | |
  40. | long FAR PASCAL muldiv32(long, long, long) |
  41. | long l; |
  42. | long Numer; |
  43. | long Denom; |
  44. | { |
  45. | |
  46. | Sign = sign of Denom; // Sign will keep track of final sign // |
  47. | |
  48. | |
  49. | if (Denom < 0) |
  50. | { |
  51. | negate Denom; // make sure Denom is positive // |
  52. | } |
  53. | |
  54. | if (l < 0) |
  55. | { |
  56. | negate l; // make sure l is positive // |
  57. | } |
  58. | |
  59. | make Sign reflect any sign change; |
  60. | |
  61. | |
  62. | if (Numer < 0) |
  63. | { |
  64. | negate Numer; // make sure Numer is positive // |
  65. | } |
  66. | |
  67. | make Sign reflect any sign change; |
  68. | |
  69. | Numer *= l; |
  70. | Numer += (Denom/2); // adjust for rounding // |
  71. | |
  72. | if (overflow) // check for overflow, and handle divide by zero //|
  73. | { |
  74. | jump to md5; |
  75. | } |
  76. | |
  77. | result = Numer/Denom; |
  78. | |
  79. | if (overflow) // check again to see if overflow occured // |
  80. | { |
  81. | jump to md5; |
  82. | } |
  83. | |
  84. | if (Sign is negative) // put sign on the result // |
  85. | { |
  86. | negate result; |
  87. | } |
  88. | |
  89. |md6: |
  90. | return(result); |
  91. | |
  92. |md5: |
  93. | DX = 7FFF; // indicate overflow by // |
  94. | AX = 0xFFFF // return largest integer // |
  95. | if (Sign is negative) |
  96. | { |
  97. | DX = 0x8000; // with correct sign // |
  98. | AX = 0x0000; |
  99. | } |
  100. | |
  101. | jump to md6; |
  102. | } |
  103. \-----------------------------------------------------------------------------*/
  104. #include <windows.h>
  105. LONG FAR PASCAL muldiv32(long l, long Numer, long Denom)
  106. {
  107. return( (l*Numer)/Denom);
  108. }