3 * @copy 2012 MinGW.org project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 #pragma GCC system_header
30 * Header for 64 bit integer arithmetics library
40 #define _toi (__int64)
41 #define _toui (unsigned __int64)
43 #error "64 bit integers not supported"
47 We don't let the compiler see the prototypes if we are compiling the
48 library because if it does it will choke on conflicting types in the
52 #if defined(LARGEINT_PROTOS) || defined(__COMPILING_LARGEINT)
54 #ifndef __COMPILING_LARGEINT
55 /* addition/subtraction */
56 LARGE_INTEGER WINAPI LargeIntegerAdd (LARGE_INTEGER, LARGE_INTEGER);
57 LARGE_INTEGER WINAPI LargeIntegerSubtract (LARGE_INTEGER, LARGE_INTEGER);
60 LARGE_INTEGER WINAPI LargeIntegerArithmeticShift (LARGE_INTEGER, int);
61 LARGE_INTEGER WINAPI LargeIntegerShiftLeft (LARGE_INTEGER, int);
62 LARGE_INTEGER WINAPI LargeIntegerShiftRight (LARGE_INTEGER, int);
63 LARGE_INTEGER WINAPI LargeIntegerNegate (LARGE_INTEGER);
66 LARGE_INTEGER WINAPI ConvertLongToLargeInteger (LONG);
67 LARGE_INTEGER WINAPI ConvertUlongToLargeInteger (ULONG);
70 LARGE_INTEGER WINAPI EnlargedIntegerMultiply (LONG, LONG);
71 LARGE_INTEGER WINAPI EnlargedUnsignedMultiply (ULONG, ULONG);
72 LARGE_INTEGER WINAPI ExtendedIntegerMultiply (LARGE_INTEGER, LONG);
73 /* FIXME: is this not part of largeint? */
74 LARGE_INTEGER WINAPI LargeIntegerMultiply (LARGE_INTEGER, LARGE_INTEGER);
75 #endif /* __COMPILING_LARGEINT */
79 #define LargeIntegerAdd(a,b) (LARGE_INTEGER)(_toi(a) + _toi(b))
80 #define LargeIntegerSubtract(a,b) (LARGE_INTEGER)(_toi(a) - _toi(b))
81 #define LargeIntegerRightShift(i,n) (LARGE_INTEGER)(_toi(i) >> (n))
82 #define LargeIntegerArithmeticShift LargeIntegerRightShift
83 #define LargeIntegerLeftShift(i,n) (LARGE_INTEGER)(_toi(i) << (n))
84 #define LargeIntegerNegate(i) (LARGE_INTEGER)(- _toi(i))
85 #define EnlargedIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
86 #define EnlargedUnsignedMultiply(a,b) (LARGE_INTEGER)(_toui(a) * _toui(b))
87 #define ExtendedIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
88 /* FIXME: should this exist */
89 #define LargeIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
90 #define ConvertLongToLargeInteger(l) (LARGE_INTEGER)(_toi(l))
91 #define ConvertUlongToLargeInteger(ul) (LARGE_INTEGER)(_toui(ul))
93 #endif /* LARGEINT_PROTOS || __COMPILING_LARGEINT */
95 #ifndef __COMPILING_LARGEINT
96 /* division; no macros of these because of multiple expansion */
97 LARGE_INTEGER WINAPI LargeIntegerDivide (LARGE_INTEGER, LARGE_INTEGER, PLARGE_INTEGER);
98 ULONG WINAPI EnlargedUnsignedDivide (ULARGE_INTEGER, ULONG, PULONG);
99 LARGE_INTEGER WINAPI ExtendedLargeIntegerDivide (LARGE_INTEGER, ULONG, PULONG);
100 LARGE_INTEGER WINAPI ExtendedMagicDivide (LARGE_INTEGER, LARGE_INTEGER, int);
101 #endif /* __COMPILING_LARGEINT */
103 #define LargeIntegerAnd(dest, src, m) \
105 dest._STRUCT_NAME(u.)LowPart = s._STRUCT_NAME(u.)LowPart & m._STRUCT_NAME(u.)LowPart; \
106 dest._STRUCT_NAME(u.)HighPart = s._STRUCT_NAME(u.)HighPart & m._STRUCT_NAME(u.)HighPart; \
110 #define LargeIntegerGreaterThan(a,b) (_toi(a) > _toi(b))
111 #define LargeIntegerGreaterThanOrEqual(a,b) (_toi(a) >= _toi(b))
112 #define LargeIntegerEqualTo(a,b) (_toi(a) == _toi(b))
113 #define LargeIntegerNotEqualTo(a,b) (_toi(a) != _toi(b))
114 #define LargeIntegerLessThan(a,b) (_toi(a) < _toi(b))
115 #define LargeIntegerLessThanOrEqualTo(a,b) (_toi(a) <= _toi(b))
116 #define LargeIntegerGreaterThanZero(a) (_toi(a) > 0)
117 #define LargeIntegerGreaterOrEqualToZero(a) ((a)._STRUCT_NAME(u.)HighPart > 0)
118 #define LargeIntegerEqualToZero(a) !((a)._STRUCT_NAME(u.)LowPart | (a)._STRUCT_NAME(u.)HighPart)
119 #define LargeIntegerNotEqualToZero(a) ((a)._STRUCT_NAME(u.)LowPart | (a)._STRUCT_NAME(u.)HighPart)
120 #define LargeIntegerLessThanZero(a) ((a)._STRUCT_NAME(u.)HighPart < 0)
121 #define LargeIntegerLessOrEqualToZero(a) (_toi(a) <= 0)
123 #ifndef __COMPILING_LARGEINT
132 #endif /* _LARGEINT_H */