00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __UT_VeryLong__
00020 #define __UT_VeryLong__
00021
00022 #include "UT_API.h"
00023 #include <SYS/SYS_Types.h>
00024 class ut_VeryLongValue;
00025 class UT_VeryLong;
00026 class UT_PolyField;
00027 class UT_BitStream;
00028
00029 UT_API UT_VeryLong operator+(const UT_VeryLong &x, const UT_VeryLong &y);
00030 UT_API UT_VeryLong operator-(const UT_VeryLong &x, const UT_VeryLong &y);
00031 UT_API UT_VeryLong operator*(const UT_VeryLong &x, const UT_VeryLong &y);
00032 UT_API UT_VeryLong operator/(const UT_VeryLong &x, const UT_VeryLong &y);
00033 UT_API UT_VeryLong operator%(const UT_VeryLong &x, const UT_VeryLong &y);
00034 UT_API UT_VeryLong operator<<(const UT_VeryLong &x, unsigned int shift);
00035 UT_API UT_VeryLong operator>>(const UT_VeryLong &x, unsigned int shift);
00036
00037 class UT_API UT_VeryLong
00038 {
00039 public:
00040 UT_VeryLong(uint x=0);
00041 UT_VeryLong(const UT_VeryLong &x);
00042 UT_VeryLong(const UT_PolyField &x);
00043 UT_VeryLong(const uint32 *data, int nwords);
00044 UT_VeryLong(const char *string);
00045 ~UT_VeryLong();
00046
00047 UT_VeryLong &operator=(const UT_VeryLong &x);
00048 UT_VeryLong &operator=(uint x);
00049 UT_VeryLong &operator=(const char *x);
00050
00051
00052 UT_VeryLong &operator+=(const UT_VeryLong &x);
00053 UT_VeryLong &operator-=(const UT_VeryLong &x);
00054 UT_VeryLong &operator^=(const UT_VeryLong &x);
00055 UT_VeryLong &operator|=(const UT_VeryLong &x);
00056 UT_VeryLong &operator*=(const UT_VeryLong &x);
00057 UT_VeryLong &operator/=(const UT_VeryLong &x);
00058 UT_VeryLong &operator%=(const UT_VeryLong &x);
00059 UT_VeryLong &operator<<=(uint shift);
00060 UT_VeryLong &operator>>=(uint shift);
00061
00062 static UT_VeryLong modexp(const UT_VeryLong &x,
00063 const UT_VeryLong &e,
00064 const UT_VeryLong &m);
00065
00066 static UT_VeryLong gcd(const UT_VeryLong &X, const UT_VeryLong &Y);
00067
00068
00069 static UT_VeryLong modinv( const UT_VeryLong &a, const UT_VeryLong &m );
00070
00071
00072 friend inline int operator !=( const UT_VeryLong& x, const UT_VeryLong& y )
00073 { return x.cf(y) != 0; }
00074
00075 friend inline int operator ==( const UT_VeryLong& x, const UT_VeryLong& y )
00076 { return x.cf(y) == 0; }
00077
00078 friend inline int operator >=( const UT_VeryLong& x, const UT_VeryLong& y )
00079 { return x.cf(y) >= 0; }
00080
00081 friend inline int operator <=( const UT_VeryLong& x, const UT_VeryLong& y )
00082 { return x.cf(y) <= 0; }
00083
00084 friend inline int operator > ( const UT_VeryLong& x, const UT_VeryLong& y )
00085 { return x.cf(y) > 0; }
00086
00087 friend inline int operator < ( const UT_VeryLong& x, const UT_VeryLong& y )
00088 { return x.cf(y) < 0; }
00089
00090 operator unsigned();
00091
00092
00093
00094 int divideBy(uint base=10);
00095
00096 int getNumBits() const;
00097 int getBit(int i) const;
00098
00099 int isZero() const;
00100
00101 ut_VeryLongValue *getValue() { return myValue; }
00102 const ut_VeryLongValue *getValue() const { return myValue; }
00103 int getNegative() const { return myNegative; }
00104 void setNegative(int n) { myNegative = n; }
00105
00106 void printVariable(const char *name) const;
00107
00108
00109 void print( const char *prefix=0,
00110 int radix=16,
00111 const char *suffix="\n" ) const;
00112
00113 void saveToBitStream(UT_BitStream &bs, int nbits) const;
00114 void loadFromBitStream(UT_BitStream &bs, int nbits);
00115
00116 uint getLow32Bits() const;
00117 const uint *getData(uint &len) const;
00118 void setData(const uint *data, uint len);
00119
00120 private:
00121 int cf(const UT_VeryLong &x) const;
00122 void harden();
00123
00124 ut_VeryLongValue *myValue;
00125 int myNegative;
00126
00127 friend class ut_MMExp;
00128 friend class UT_PolyField;
00129 };
00130
00131 #endif