Replaced Exit() by exit() because Exit() is like abort().
[AROS-Contrib.git] / scout / source / i64.h
blob83c16f3577a46aeb5e3cc7b92ddcbe14746ec997
1 /* i64.h */
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.
24 $RCSfile: i64.h,v $
25 $Revision$
26 $Date$
27 \*--------------------------------------------------------------------------*/
29 #ifndef I64_MATH
30 #define I64_MATH
32 typedef struct {
33 unsigned hi; /* Most significant 32 bits */
34 unsigned lo; /* Least significant 32 bits */
35 } bigint;
38 /* Compare n1 and n2.
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);
45 #define I64_GREATER 1
46 #define I64_LESS -1
47 #define I64_EQUAL 0
49 /* Sign of n
51 * Returns 1 if n > 0
52 * Returns -1 if n < 0
53 * Returns 0 if n = 0
55 int i64_sgn(bigint n);
57 /* Left shift
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);
73 /* Signed right shift
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);
82 /* Change sign of n
84 * Returns -n
86 bigint i64_inv(bigint n);
88 /* Add n1 and n2
90 * Returns n1 + n2
92 bigint i64_add(bigint n1, bigint n2);
94 /* Subtract n2 from n1
96 * Returns n1 - n2
98 bigint i64_sub(bigint n1, bigint n2);
100 /* Multiply n1 and n2
102 * Returns n1 * 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
127 * Returns 0 on error
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 );
149 #endif