source: Daodan/MinGW/include/largeint.h@ 1054

Last change on this file since 1054 was 1046, checked in by alloc, 8 years ago

Daodan: Added Windows MinGW and build batch file

File size: 4.0 KB
Line 
1/*
2 largeint.h
3
4 Header for 64 bit integer arithmetics library
5
6 */
7#ifndef _LARGEINT_H
8#define _LARGEINT_H
9#if __GNUC__ >=3
10#pragma GCC system_header
11#endif
12
13#include <windows.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#ifdef _HAVE_INT64
20#define _toi (__int64)
21#define _toui (unsigned __int64)
22#else
23#error "64 bit integers not supported"
24#endif
25
26/*
27 We don't let the compiler see the prototypes if we are compiling the
28 library because if it does it will choke on conflicting types in the
29 prototypes.
30*/
31
32#if defined(LARGEINT_PROTOS) || defined(__COMPILING_LARGEINT)
33
34#ifndef __COMPILING_LARGEINT
35/* addition/subtraction */
36LARGE_INTEGER WINAPI LargeIntegerAdd (LARGE_INTEGER, LARGE_INTEGER);
37LARGE_INTEGER WINAPI LargeIntegerSubtract (LARGE_INTEGER, LARGE_INTEGER);
38
39/* bit operations */
40LARGE_INTEGER WINAPI LargeIntegerArithmeticShift (LARGE_INTEGER, int);
41LARGE_INTEGER WINAPI LargeIntegerShiftLeft (LARGE_INTEGER, int);
42LARGE_INTEGER WINAPI LargeIntegerShiftRight (LARGE_INTEGER, int);
43LARGE_INTEGER WINAPI LargeIntegerNegate (LARGE_INTEGER);
44
45/* conversion */
46LARGE_INTEGER WINAPI ConvertLongToLargeInteger (LONG);
47LARGE_INTEGER WINAPI ConvertUlongToLargeInteger (ULONG);
48
49/* multiplication */
50LARGE_INTEGER WINAPI EnlargedIntegerMultiply (LONG, LONG);
51LARGE_INTEGER WINAPI EnlargedUnsignedMultiply (ULONG, ULONG);
52LARGE_INTEGER WINAPI ExtendedIntegerMultiply (LARGE_INTEGER, LONG);
53/* FIXME: is this not part of largeint? */
54LARGE_INTEGER WINAPI LargeIntegerMultiply (LARGE_INTEGER, LARGE_INTEGER);
55#endif /* __COMPILING_LARGEINT */
56
57#else
58
59#define LargeIntegerAdd(a,b) (LARGE_INTEGER)(_toi(a) + _toi(b))
60#define LargeIntegerSubtract(a,b) (LARGE_INTEGER)(_toi(a) - _toi(b))
61#define LargeIntegerRightShift(i,n) (LARGE_INTEGER)(_toi(i) >> (n))
62#define LargeIntegerArithmeticShift LargeIntegerRightShift
63#define LargeIntegerLeftShift(i,n) (LARGE_INTEGER)(_toi(i) << (n))
64#define LargeIntegerNegate(i) (LARGE_INTEGER)(- _toi(i))
65#define EnlargedIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
66#define EnlargedUnsignedMultiply(a,b) (LARGE_INTEGER)(_toui(a) * _toui(b))
67#define ExtendedIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
68/* FIXME: should this exist */
69#define LargeIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
70#define ConvertLongToLargeInteger(l) (LARGE_INTEGER)(_toi(l))
71#define ConvertUlongToLargeInteger(ul) (LARGE_INTEGER)(_toui(ul))
72
73#endif /* LARGEINT_PROTOS || __COMPILING_LARGEINT */
74
75#ifndef __COMPILING_LARGEINT
76/* division; no macros of these because of multiple expansion */
77LARGE_INTEGER WINAPI LargeIntegerDivide (LARGE_INTEGER, LARGE_INTEGER, PLARGE_INTEGER);
78ULONG WINAPI EnlargedUnsignedDivide (ULARGE_INTEGER, ULONG, PULONG);
79LARGE_INTEGER WINAPI ExtendedLargeIntegerDivide (LARGE_INTEGER, ULONG, PULONG);
80LARGE_INTEGER WINAPI ExtendedMagicDivide (LARGE_INTEGER, LARGE_INTEGER, int);
81#endif /* __COMPILING_LARGEINT */
82
83#define LargeIntegerAnd(dest, src, m) \
84{ \
85 dest._STRUCT_NAME(u.)LowPart = s._STRUCT_NAME(u.)LowPart & m._STRUCT_NAME(u.)LowPart; \
86 dest._STRUCT_NAME(u.)HighPart = s._STRUCT_NAME(u.)HighPart & m._STRUCT_NAME(u.)HighPart; \
87}
88
89/* comparision */
90#define LargeIntegerGreaterThan(a,b) (_toi(a) > _toi(b))
91#define LargeIntegerGreaterThanOrEqual(a,b) (_toi(a) >= _toi(b))
92#define LargeIntegerEqualTo(a,b) (_toi(a) == _toi(b))
93#define LargeIntegerNotEqualTo(a,b) (_toi(a) != _toi(b))
94#define LargeIntegerLessThan(a,b) (_toi(a) < _toi(b))
95#define LargeIntegerLessThanOrEqualTo(a,b) (_toi(a) <= _toi(b))
96#define LargeIntegerGreaterThanZero(a) (_toi(a) > 0)
97#define LargeIntegerGreaterOrEqualToZero(a) ((a)._STRUCT_NAME(u.)HighPart > 0)
98#define LargeIntegerEqualToZero(a) !((a)._STRUCT_NAME(u.)LowPart | (a)._STRUCT_NAME(u.)HighPart)
99#define LargeIntegerNotEqualToZero(a) ((a)._STRUCT_NAME(u.)LowPart | (a)._STRUCT_NAME(u.)HighPart)
100#define LargeIntegerLessThanZero(a) ((a)._STRUCT_NAME(u.)HighPart < 0)
101#define LargeIntegerLessOrEqualToZero(a) (_toi(a) <= 0)
102
103#ifndef __COMPILING_LARGEINT
104#undef _toi
105#undef _toui
106#endif
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif /* _LARGEINT_H */
Note: See TracBrowser for help on using the repository browser.