1 /* Copyright Digital Equipment Corporation & INRIA 1988, 1989 */
2 /* Last modified_on Fri Aug 17 17:19:01 GMT+2:00 1990 by shand */
3 /* modified_on Wed Jul 5 10:19:33 GMT+2:00 1989 by bertin */
4 /* modified_on Fri Apr 28 20:03:23 GMT+2:00 1989 by herve */
7 /* BigN.h - Types and structures for clients of BigNum */
11 /******** representation of a bignum ******/
13 ** <--------------------------- nl ---------------------------->
15 ** |Significant| | | |Significant|
16 ** |BigNumDigit| | | |BigNumDigit|
17 ** |___________|___________|___________|___________|___________|
23 /* signals BigNum.h already included */
26 /*************** sizes ********************/
28 #define BN_BYTE_SIZE 8
29 #define BN_WORD_SIZE (sizeof (int) * BN_BYTE_SIZE)
30 #define BN_DIGIT_SIZE (sizeof (BigNumDigit) * BN_BYTE_SIZE)
33 /* BN_BYTE_SIZE: number of bits in a byte */
34 /* BN_WORD_SIZE: number of bits in an "int" in the target language */
35 /* BN_DIGIT_SIZE: number of bits in a digit of a BigNum */
38 /****** results of compare functions ******/
40 /* Note: we don't use "enum" to interface with Modula2+, Lisp, ... */
45 /*************** boolean ******************/
51 /* if DIGITon16BITS is defined, a single digit is on 16 bits */
52 /* otherwise (by default) a single digit is on 32 bits *****/
53 /* Note: on 32 bit machine it makes little sense to mix */
54 /* longs and short, so we define Boolean & BigNumCmp to be */
58 typedef unsigned short BigNumDigit;
59 typedef short Boolean;
61 typedef unsigned int BigNumDigit;
66 /* bignum types: digits, big numbers, carries ... */
68 typedef BigNumDigit * BigNum; /* A big number is a digit pointer */
69 typedef BigNumDigit BigNumCarry; /* Either 0 or 1 */
70 typedef unsigned long BigNumProduct; /* The product of two digits */
71 typedef unsigned long BigNumLength; /* The length of a bignum */
73 typedef short BigNumCmp; /* result of comparison */
75 typedef int BigNumCmp; /* result of comparison */
82 /************ functions of bn.c ***********/
84 extern void BnnInit ();
85 extern void BnnClose ();
87 extern Boolean BnnIsZero ();
88 extern BigNumCarry BnnMultiply ();
89 extern void BnnDivide ();
90 extern BigNumCmp BnnCompare ();
93 /*********** functions of KerN.c **********/
95 extern void BnnSetToZero ();
96 extern void BnnAssign ();
97 extern void BnnSetDigit ();
98 extern BigNumDigit BnnGetDigit ();
99 extern BigNumLength BnnNumDigits ();
100 extern BigNumDigit BnnNumLeadingZeroBitsInDigit ();
101 extern Boolean BnnDoesDigitFitInWord ();
102 extern Boolean BnnIsDigitZero ();
103 extern Boolean BnnIsDigitNormalized ();
104 extern Boolean BnnIsDigitOdd ();
105 extern BigNumCmp BnnCompareDigits ();
106 extern void BnnComplement ();
107 extern void BnnAndDigits ();
108 extern void BnnOrDigits ();
109 extern void BnnXorDigits ();
110 extern BigNumDigit BnnShiftLeft ();
111 extern BigNumDigit BnnShiftRight ();
112 extern BigNumCarry BnnAddCarry ();
113 extern BigNumCarry BnnAdd ();
114 extern BigNumCarry BnnSubtractBorrow ();
115 extern BigNumCarry BnnSubtract ();
116 extern BigNumCarry BnnMultiplyDigit ();
117 extern BigNumDigit BnnDivideDigit ();
121 /* some functions can be written with macro-procedures */
124 #ifndef BNNMACROS_OFF
125 /* the functions BnnIsZero and BnnCompareDigits are not macro procedures
126 since they use parameters twice, and that can produce some bugs if
127 you pass a parameter like x++, the increment will be executed twice ! */
128 #define BnnSetDigit(nn,d) (*(nn) = (d))
129 #define BnnGetDigit(nn) ((unsigned)(*(nn)))
130 #define BnnDoesDigitFitInWord(d) (BN_DIGIT_SIZE > BN_WORD_SIZE ? ((d) >= 1 << BN_WORD_SIZE ? FALSE : TRUE) : TRUE)
131 #define BnnIsDigitZero(d) ((d) == 0)
132 #define BnnIsDigitNormalized(d) ((d) & (1 << (BN_DIGIT_SIZE - 1)) ? TRUE : FALSE)
133 #define BnnIsDigitOdd(d) ((d) & 1 ? TRUE : FALSE)
134 #define BnnAndDigits(nn, d) (*(nn) &= (d))
135 #define BnnOrDigits(nn, d) (*(nn) |= (d))
136 #define BnnXorDigits(nn, d) (*(nn) ^= (d))