Install w32api-3.13-mingw32-dev.tar.gz
[git/jnareb-git.git] / mingw / include / largeint.h
blobb2222a97fc5a591bddc4d159843597c237f3627a
1 /*
2 largeint.h
4 Header for 64 bit integer arithmetics library
6 */
7 #ifndef _LARGEINT_H
8 #define _LARGEINT_H
9 #if __GNUC__ >=3
10 #pragma GCC system_header
11 #endif
13 #include <windows.h>
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
19 #ifdef _HAVE_INT64
20 #define _toi (__int64)
21 #define _toui (unsigned __int64)
22 #else
23 #error "64 bit integers not supported"
24 #endif
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.
32 #if defined(LARGEINT_PROTOS) || defined(__COMPILING_LARGEINT)
34 #ifndef __COMPILING_LARGEINT
35 /* addition/subtraction */
36 LARGE_INTEGER WINAPI LargeIntegerAdd (LARGE_INTEGER, LARGE_INTEGER);
37 LARGE_INTEGER WINAPI LargeIntegerSubtract (LARGE_INTEGER, LARGE_INTEGER);
39 /* bit operations */
40 LARGE_INTEGER WINAPI LargeIntegerArithmeticShift (LARGE_INTEGER, int);
41 LARGE_INTEGER WINAPI LargeIntegerShiftLeft (LARGE_INTEGER, int);
42 LARGE_INTEGER WINAPI LargeIntegerShiftRight (LARGE_INTEGER, int);
43 LARGE_INTEGER WINAPI LargeIntegerNegate (LARGE_INTEGER);
45 /* conversion */
46 LARGE_INTEGER WINAPI ConvertLongToLargeInteger (LONG);
47 LARGE_INTEGER WINAPI ConvertUlongToLargeInteger (ULONG);
49 /* multiplication */
50 LARGE_INTEGER WINAPI EnlargedIntegerMultiply (LONG, LONG);
51 LARGE_INTEGER WINAPI EnlargedUnsignedMultiply (ULONG, ULONG);
52 LARGE_INTEGER WINAPI ExtendedIntegerMultiply (LARGE_INTEGER, LONG);
53 /* FIXME: is this not part of largeint? */
54 LARGE_INTEGER WINAPI LargeIntegerMultiply (LARGE_INTEGER, LARGE_INTEGER);
55 #endif /* __COMPILING_LARGEINT */
57 #else
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))
73 #endif /* LARGEINT_PROTOS || __COMPILING_LARGEINT */
75 #ifndef __COMPILING_LARGEINT
76 /* division; no macros of these because of multiple expansion */
77 LARGE_INTEGER WINAPI LargeIntegerDivide (LARGE_INTEGER, LARGE_INTEGER, PLARGE_INTEGER);
78 ULONG WINAPI EnlargedUnsignedDivide (ULARGE_INTEGER, ULONG, PULONG);
79 LARGE_INTEGER WINAPI ExtendedLargeIntegerDivide (LARGE_INTEGER, ULONG, PULONG);
80 LARGE_INTEGER WINAPI ExtendedMagicDivide (LARGE_INTEGER, LARGE_INTEGER, int);
81 #endif /* __COMPILING_LARGEINT */
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; \
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)
103 #ifndef __COMPILING_LARGEINT
104 #undef _toi
105 #undef _toui
106 #endif
108 #ifdef __cplusplus
110 #endif
112 #endif /* _LARGEINT_H */