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 
41  UT_VeryLong &operator=(const char *x);
42 
43  // Standard arithmetic operators
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:561
OIIO_FORCEINLINE const vint4 & operator/=(vint4 &a, const vint4 &b)
Definition: simd.h:4438
OIIO_FORCEINLINE const vint4 & operator>>=(vint4 &a, const unsigned int bits)
Definition: simd.h:4532
OrtDmlDeviceFilter & operator^=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)
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:577
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define UT_API
Definition: UT_API.h:14
GLint y
Definition: glcorearb.h:103
OIIO_FORCEINLINE vbool4 operator>=(const vint4 &a, const vint4 &b)
Definition: simd.h:4577
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
OIIO_FORCEINLINE vbool4 operator>(const vint4 &a, const vint4 &b)
Definition: simd.h:4561
GLdouble n
Definition: glcorearb.h:2008
OIIO_FORCEINLINE vbool4 operator<=(const vint4 &a, const vint4 &b)
Definition: simd.h:4581
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:587
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4369
int getNegative() const
Definition: UT_VeryLong.h:95
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
GLuint const GLchar * name
Definition: glcorearb.h:786
GLint GLenum GLint x
Definition: glcorearb.h:409
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
Definition: ImathMatrix.h:4660
const ut_VeryLongValue * getValue() const
Definition: UT_VeryLong.h:94
OIIO_FORCEINLINE const vint4 & operator<<=(vint4 &a, const unsigned int bits)
Definition: simd.h:4519
LeafData & operator=(const LeafData &)=delete
UT_API UT_VeryLong operator<<(const UT_VeryLong &x, unsigned int shift)
unsigned int uint32
Definition: SYS_Types.h:40
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
Definition: simd.h:4392
UT_API UT_VeryLong operator>>(const UT_VeryLong &x, unsigned int shift)
void setNegative(int n)
Definition: UT_VeryLong.h:96
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2976
UT_API UT_VeryLong operator%(const UT_VeryLong &x, const UT_VeryLong &y)
unsigned int uint
Definition: SYS_Types.h:45
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:337
Definition: format.h:895
OrtDmlDeviceFilter & operator|=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)
OIIO_FORCEINLINE const vint4 & operator%=(vint4 &a, const vint4 &b)
Definition: simd.h:4447