Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

divlarge.c File Reference

#include "ntrtlp.h"

Go to the source code of this file.

Functions

LARGE_INTEGER RtlLargeIntegerDivide (IN LARGE_INTEGER Dividend, IN LARGE_INTEGER Divisor, OUT PLARGE_INTEGER Remainder OPTIONAL)


Function Documentation

LARGE_INTEGER RtlLargeIntegerDivide IN LARGE_INTEGER  Dividend,
IN LARGE_INTEGER  Divisor,
OUT PLARGE_INTEGER Remainder  OPTIONAL
 

Definition at line 28 of file divlarge.c.

References Index, and RtlRaiseStatus().

00036 : 00037 00038 This routine divides an unsigned 64-bit dividend by an unsigned 64-bit 00039 divisor and returns a 64-bit quotient, and optionally a 64-bit remainder. 00040 00041 Arguments: 00042 00043 Dividend - Supplies the 64-bit dividend for the divide operation. 00044 00045 Divisor - Supplies the 64-bit divisor for the divide operation. 00046 00047 Remainder - Supplies an optional pointer to a variable which receives 00048 the remainder 00049 00050 Return Value: 00051 00052 The 64-bit quotient is returned as the function value. 00053 00054 --*/ 00055 00056 { 00057 00058 ULONG Index = 64; 00059 LARGE_INTEGER Partial = {0, 0}; 00060 LARGE_INTEGER Quotient; 00061 00062 #ifndef BLDR_KERNEL_RUNTIME 00063 // 00064 // Check for divide by zero 00065 // 00066 00067 if (!(Divisor.LowPart | Divisor.HighPart)) { 00068 RtlRaiseStatus (STATUS_INTEGER_DIVIDE_BY_ZERO); 00069 } 00070 #endif 00071 00072 // 00073 // Loop through the dividend bits and compute the quotient and remainder. 00074 // 00075 00076 Quotient = Dividend; 00077 do { 00078 00079 // 00080 // Shift the next dividend bit into the parital remainder and shift 00081 // the partial quotient (dividend) left one bit. 00082 // 00083 00084 Partial.HighPart = (Partial.HighPart << 1) | (Partial.LowPart >> 31); 00085 Partial.LowPart = (Partial.LowPart << 1) | ((ULONG)Quotient.HighPart >> 31); 00086 Quotient.HighPart = (Quotient.HighPart << 1) | (Quotient.LowPart >> 31); 00087 Quotient.LowPart <<= 1; 00088 00089 // 00090 // If the partial remainder is greater than or equal to the divisor, 00091 // then subtract the divisor from the partial remainder and insert a 00092 // one bit into the quotient. 00093 // 00094 00095 if (((ULONG)Partial.HighPart > (ULONG)Divisor.HighPart) || 00096 ((Partial.HighPart == Divisor.HighPart) && 00097 (Partial.LowPart >= Divisor.LowPart))) { 00098 00099 Quotient.LowPart |= 1; 00100 Partial.HighPart -= Divisor.HighPart; 00101 if (Partial.LowPart < Divisor.LowPart) { 00102 Partial.HighPart -= 1; 00103 } 00104 00105 Partial.LowPart -= Divisor.LowPart; 00106 } 00107 00108 Index -= 1; 00109 } while (Index > 0); 00110 00111 // 00112 // If the remainder is requested, then return the 64-bit remainder. 00113 // 00114 00115 if (ARGUMENT_PRESENT(Remainder)) { 00116 *Remainder = Partial; 00117 } 00118 00119 // 00120 // Return the 64-bit quotient. 00121 // 00122 00123 return Quotient; 00124 } }


Generated on Sat May 15 19:43:27 2004 for test by doxygen 1.3.7