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

recip.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1989 Microsoft Corporation 00004 00005 Module Name: 00006 00007 recip.c 00008 00009 Abstract: 00010 00011 This module generates reciprocol fractions for implementing integer 00012 division by multiplication. 00013 00014 Author: 00015 00016 David N. Cutler (davec) 13-May-1989 00017 00018 Environment: 00019 00020 User mode. 00021 00022 Revision History: 00023 00024 --*/ 00025 00026 #include <stdio.h> 00027 00028 typedef struct _large_integer { 00029 unsigned long LowPart; 00030 long HighPart; 00031 } large_integer; 00032 00033 //long Divisors[] = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 0}; 00034 long Divisors[] = {10, 10000, 10000000, 86400000, 0}; 00035 00036 void 00037 main (argc, argv) 00038 int argc; 00039 char *argv[]; 00040 { 00041 00042 large_integer Fraction; 00043 long Index; 00044 long NumberBits; 00045 long Remainder; 00046 00047 long i; 00048 00049 // 00050 // Compute first few reciprocols. 00051 // 00052 00053 for (Index = Divisors[i = 0]; Index != 0L; Index = Divisors[++i]) { 00054 NumberBits = 0L; 00055 Remainder = 1L; 00056 Fraction.LowPart = 0L; 00057 Fraction.HighPart = 0L; 00058 while (Fraction.HighPart >= 0L) { 00059 NumberBits += 1L; 00060 Fraction.HighPart <<= 1L; 00061 if ((Fraction.LowPart & 0x80000000) != 0L) { 00062 Fraction.HighPart += 1L; 00063 } 00064 Fraction.LowPart <<= 1L; 00065 Remainder <<= 1L; 00066 if (Remainder >= Index) { 00067 Remainder -= Index; 00068 Fraction.LowPart |= 1L; 00069 } 00070 } 00071 if (Remainder) { 00072 if ((Fraction.LowPart == -1L) && (Fraction.HighPart == -1L)) { 00073 Fraction.LowPart = 0L; 00074 Fraction.HighPart = 0x80000000; 00075 NumberBits -= 1L; 00076 } else { 00077 if (Fraction.LowPart == -1L) { 00078 Fraction.LowPart = 0L; 00079 Fraction.HighPart += 1L; 00080 } else { 00081 Fraction.LowPart += 1L; 00082 } 00083 } 00084 } 00085 00086 printf("Divisor %2ld, Fraction %8lx, %8lx Shift %ld\n", Index, 00087 Fraction.HighPart, Fraction.LowPart, NumberBits - 64L); 00088 } 00089 00090 return; 00091 } 00092

Generated on Sat May 15 19:41:37 2004 for test by doxygen 1.3.7