00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00051
00052
00053
for (
Index =
Divisors[i = 0];
Index != 0
L;
Index =
Divisors[++i]) {
00054 NumberBits = 0
L;
00055 Remainder = 1
L;
00056 Fraction.
LowPart = 0
L;
00057 Fraction.
HighPart = 0
L;
00058
while (Fraction.
HighPart >= 0
L) {
00059 NumberBits += 1
L;
00060 Fraction.
HighPart <<= 1
L;
00061
if ((Fraction.
LowPart & 0x80000000) != 0
L) {
00062 Fraction.
HighPart += 1
L;
00063 }
00064 Fraction.
LowPart <<= 1
L;
00065 Remainder <<= 1
L;
00066
if (Remainder >=
Index) {
00067 Remainder -=
Index;
00068 Fraction.
LowPart |= 1
L;
00069 }
00070 }
00071
if (Remainder) {
00072
if ((Fraction.
LowPart == -1
L) && (Fraction.
HighPart == -1
L)) {
00073 Fraction.
LowPart = 0
L;
00074 Fraction.
HighPart = 0x80000000;
00075 NumberBits -= 1
L;
00076 }
else {
00077
if (Fraction.
LowPart == -1
L) {
00078 Fraction.
LowPart = 0
L;
00079 Fraction.
HighPart += 1
L;
00080 }
else {
00081 Fraction.
LowPart += 1
L;
00082 }
00083 }
00084 }
00085
00086 printf(
"Divisor %2ld, Fraction %8lx, %8lx Shift %ld\n",
Index,
00087 Fraction.
HighPart, Fraction.
LowPart, NumberBits - 64
L);
00088 }
00089
00090
return;
00091 }
00092