2 /*--------------------------------------------------------------------------*\
3 Copyright (C) 1999 Douglas W. Sauder
5 This software is provided "as is," without any express or implied
6 warranty. In no event will the author be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
21 The original distribution can be obtained from www.hunnysoft.com.
22 You can email the author at dwsauder@erols.com.
27 \*--------------------------------------------------------------------------*/
33 unsigned hi
; /* Most significant 32 bits */
34 unsigned lo
; /* Least significant 32 bits */
39 * Returns 1 if n1 > n2
40 * Returns -1 if n1 < n2
41 * Returns 0 if n1 = n2
43 int i64_cmp(bigint n1
, bigint n2
);
55 int i64_sgn(bigint n
);
59 * Shift n to the left by b bits
61 * Undefined if b < 0 or b > 63
63 bigint
i64_lshift(bigint n
, int b
);
65 /* Unsigned right shift
67 * Shift n to the right by b bits. Zeros are shifted in.
69 * Undefined if b < 0 or b > 63
71 bigint
i64_urshift(bigint n
, int b
);
75 * Shift n to the right by b bits. Zeros or ones are shifted in, depending
76 * on the most leftmost bit in n.
78 * Undefined if b < 0 or b > 63
80 bigint
i64_srshift(bigint n
, int b
);
86 bigint
i64_inv(bigint n
);
92 bigint
i64_add(bigint n1
, bigint n2
);
94 /* Subtract n2 from n1
98 bigint
i64_sub(bigint n1
, bigint n2
);
100 /* Multiply n1 and n2
104 bigint
i64_mul(bigint multiplicand
, bigint multiplier
);
106 /* Divide dividend by divisor
108 * Returns values quotient and remainder such that
110 * dividend = (divisor * quotient) + remainder
112 void i64_div(bigint dividend
, bigint divisor
, bigint
*quotient
, bigint
*remainder
);
114 /* Divide dividend by divisor (unsigned)
116 * Returns values quotient and remainder such that
118 * dividend = (divisor * quotient) + remainder
120 * Both dividend and divisor are treated as unsigned integers
122 void i64_udiv(bigint dividend
, bigint divisor
, bigint
*quotient
, bigint
*remainder
);
124 /* Converts string to 64 bit integer
126 * Returns 64 bit integer from ASCII representation in buffer str
129 bigint
i64_atoi(const char *str
);
131 /* Converts 64 bit integer to string
133 * Fills buffer str with ASCII representation for n
135 void i64_itoa(bigint n
, char *str
, int strSize
);
138 /* Following functions added by Paul Huxham 30/12/2000 */
140 /* Set the value of a bigint from a long */
141 bigint
i64_set( long n1
);
143 /* Set the value of a bigint from a ulong */
144 bigint
i64_uset( unsigned long n1
);
146 /* Multiply two ulongs together and return a bigint */
147 bigint
i64_uumul( unsigned long n1
, unsigned long n2
);