HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_VeryLong.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: LM_VLong.h ( LM Library, C++)
7  *
8  * COMMENTS: Very long integer (used in RSA encryption/decryption)
9  */
10 
11 #ifndef __UT_VeryLong__
12 #define __UT_VeryLong__
13 
14 #include "UT_API.h"
15 #include <SYS/SYS_Types.h>
16 class ut_VeryLongValue;
17 class UT_VeryLong;
18 class UT_PolyField;
19 class UT_BitStream;
20 
26 UT_API UT_VeryLong operator<<(const UT_VeryLong &x, unsigned int shift);
27 UT_API UT_VeryLong operator>>(const UT_VeryLong &x, unsigned int shift);
28 
29 class UT_API UT_VeryLong // very long integer - can be used like long
30 {
31 public:
32  UT_VeryLong(uint x=0);
33  UT_VeryLong(const UT_VeryLong &x);
34  UT_VeryLong(const UT_PolyField &x);
35  UT_VeryLong(const uint32 *data, int nwords);
36  UT_VeryLong(const char *string);
37  ~UT_VeryLong();
38 
39  UT_VeryLong &operator=(const UT_VeryLong &x);
40  UT_VeryLong &operator=(uint x);
41  UT_VeryLong &operator=(const char *x);
42 
43  // Standard arithmetic operators
44  UT_VeryLong &operator+=(const UT_VeryLong &x);
45  UT_VeryLong &operator-=(const UT_VeryLong &x);
46  UT_VeryLong &operator^=(const UT_VeryLong &x);
47  UT_VeryLong &operator|=(const UT_VeryLong &x);
49  UT_VeryLong &operator/=(const UT_VeryLong &x);
50  UT_VeryLong &operator%=(const UT_VeryLong &x);
51  UT_VeryLong &operator<<=(uint shift);
52  UT_VeryLong &operator>>=(uint shift);
53 
54  static UT_VeryLong modexp(const UT_VeryLong &x,
55  const UT_VeryLong &e,
56  const UT_VeryLong &m); // m must be odd
57  // greatest common denominator
58  static UT_VeryLong gcd(const UT_VeryLong &X, const UT_VeryLong &Y);
59 
60  // modular inverse
61  static UT_VeryLong modinv( const UT_VeryLong &a, const UT_VeryLong &m );
62 
63  // Standard comparison operators
64  friend inline int operator !=( const UT_VeryLong& x, const UT_VeryLong& y )
65  { return x.cf(y) != 0; }
66 
67  friend inline int operator ==( const UT_VeryLong& x, const UT_VeryLong& y )
68  { return x.cf(y) == 0; }
69 
70  friend inline int operator >=( const UT_VeryLong& x, const UT_VeryLong& y )
71  { return x.cf(y) >= 0; }
72 
73  friend inline int operator <=( const UT_VeryLong& x, const UT_VeryLong& y )
74  { return x.cf(y) <= 0; }
75 
76  friend inline int operator > ( const UT_VeryLong& x, const UT_VeryLong& y )
77  { return x.cf(y) > 0; }
78 
79  friend inline int operator < ( const UT_VeryLong& x, const UT_VeryLong& y )
80  { return x.cf(y) < 0; }
81 
82  operator unsigned();
83 
84  // Used for printing out the value. This will divide the long by base and
85  // return the remainder.
86  int divideBy(uint base=10);
87 
88  int getNumBits() const;
89  int getBit(int i) const;
90 
91  int isZero() const;
92 
93  ut_VeryLongValue *getValue() { return myValue; }
94  const ut_VeryLongValue *getValue() const { return myValue; }
95  int getNegative() const { return myNegative; }
96  void setNegative(int n) { myNegative = n; }
97 
98  void printVariable(const char *name) const;
99 
100  // Radix can be between 2 and 36
101  void print( const char *prefix=0,
102  int radix=16,
103  const char *suffix="\n" ) const;
104 
105  void saveToBitStream(UT_BitStream &bs, int nbits) const;
106  void loadFromBitStream(UT_BitStream &bs, int nbits);
107 
108  uint getLow32Bits() const;
109  const uint *getData(uint &len) const;
110  void setData(const uint *data, uint len);
111 
112 private:
113  int cf(const UT_VeryLong &x) const;
114  void harden();
115 
116  ut_VeryLongValue *myValue;
117  int myNegative;
118 
119  friend class ut_MMExp;
120  friend class UT_PolyField;
121 };
122 
123 #endif
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
Definition: Mat3.h:609
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:625
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define UT_API
Definition: UT_API.h:13
GLint y
Definition: glcorearb.h:102
png_uint_32 i
Definition: png.h:2877
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GLdouble n
Definition: glcorearb.h:2007
ut_VeryLongValue * getValue()
Definition: UT_VeryLong.h:93
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:635
bool operator<=(const TfRefPtr< T > &p, std::nullptr_t)
Definition: refPtr.h:1223
int getNegative() const
Definition: UT_VeryLong.h:95
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
const Vec2< S > & operator*=(Vec2< S > &v, const Matrix33< T > &m)
Definition: ImathMatrix.h:3322
bool operator>(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:219
unsigned int uint
Definition: SYS_Types.h:40
const ut_VeryLongValue * getValue() const
Definition: UT_VeryLong.h:94
UT_API UT_VeryLong operator<<(const UT_VeryLong &x, unsigned int shift)
GLint GLenum GLint x
Definition: glcorearb.h:408
UT_API UT_VeryLong operator>>(const UT_VeryLong &x, unsigned int shift)
bool operator>=(const TfRefPtr< T > &p, std::nullptr_t)
Definition: refPtr.h:1245
void setNegative(int n)
Definition: UT_VeryLong.h:96
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
UT_API UT_VeryLong operator%(const UT_VeryLong &x, const UT_VeryLong &y)
UT_API UT_VeryLong operator/(const UT_VeryLong &x, const UT_VeryLong &y)
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:308
unsigned int uint32
Definition: SYS_Types.h:36