nmpp
tnmint.h
1//------------------------------------------------------------------------
2//
3// $Workfile:: tnmint. $
4//
5// Векторно-матричная библиотека
6//
7// Copyright (c) RC Module Inc.
8//
9// $Revision: 1.2 $ $Date: 2005/01/21 19:22:37 $
10//
20//------------------------------------------------------------------------
21
22#ifndef _TNMINT_H_INCLUDED_
23#define _TNMINT_H_INCLUDED_
24
25#ifdef __cplusplus
26//#include "tnmvecpack.h"
27
28
29
30
31
32/*
33#define CHECK_OVERFLOW_ON() _putenv("nmppsCheckOverflow_=On")
34#define CHECK_OVERFLOW_OFF() _putenv("nmppsCheckOverflow_=")
35#define ENABLE_CHECK_OVERFLOW() _putenv("nmppsCheckOverflow_=On")
36#define DISABLE_CHECK_OVERFLOW() _putenv("nmppsCheckOverflow_=")
37*/
38/*
39extern int nmppsCheckOverflow_;
40#define CHECK_OVERFLOW_ON() nmppsCheckOverflow_=1
41#define CHECK_OVERFLOW_OFF() nmppsCheckOverflow_=0
42#define ENABLE_CHECK_OVERFLOW() nmppsCheckOverflow_=1
43#define DISABLE_CHECK_OVERFLOW() nmppsCheckOverflow_=0
44
45#define CHECK_OVERFLOW() (nmppsCheckOverflow_==1) //Getting check overflow status
46*/
47
48//extern int nmppsCheckOverflow_;
49#define CHECK_OVERFLOW_ON()
50#define CHECK_OVERFLOW_OFF()
51#define ENABLE_CHECK_OVERFLOW()
52#define DISABLE_CHECK_OVERFLOW()
53
54#define CHECK_OVERFLOW() 0
55
56
57 //--------------------------------------------------------------------
60 //--------------------------------------------------------------------
61
62
63template <class T>class nmint
64{
65
66public:
67 T m_value; // m_value
68 T *m_pvalue;
69 int m_disp;
70 //---------- 0 operands constructors --------------------------------------------------
71 nmint(void):m_value(0){}
72 //---------- 1 operands constructors --------------------------------------------------
73
74 nmint(const T val)
75 {
76 m_value=val;
77 }
78
79
80 nmint<T>& operator= (const T& val)
81 {
82 m_value=val;
83 return (*this);
84 }
85
86 nmint<T>& operator= (T& val)
87 {
88 m_value=val;
89 return (*this);
90 }
91
92/*
93 nmint<T>& operator= (const nmint<T>& val)
94 {
95 m_value=val.m_value;
96 return (*this);
97 }
98
99 template <class T2> nmint<T>& operator= (const T2& value)
100 {
101 m_value=value;
102 return (*this);
103 }
104*/
105
106 nmint<T>& operator-= (const nmint<T>& val)
107 {
108 /*
109 if (CHECK_OVERFLOW())
110 {
111 __int64 tmp=m_value;
112 tmp-= val.m_value;
113 (tmp<<=(64-N))>>=(64-N);
114 if(tmp+val.m_value!=m_value)
115 OverflowMessage("Subtraction Overflow ( Res=A-B )",m_value,val.m_value,tmp,N,N,N);
116 m_value = tmp;
117 return (*this);
118 }
119 else
120 {*/
121 m_value-=val.m_value;
122 // (m_value<<=(64-N))>>=(64-N);
123 return (*this);
124 //}
125 }
126
127
128 nmint<T>& operator+= (const nmint<T>& val)
129 {
130// if (CHECK_OVERFLOW())
131// {
132// __int64 tmp=m_value;
133// tmp += val.m_value;
134// (tmp<<=(64-N))>>=(64-N);
135// if(tmp-val.m_value!=m_value)
136// OverflowMessage("Summation Overflow ( Res=A+B )",m_value,val.m_value,tmp,N,N,N);
137// m_value = tmp;
138// return (*this);
139// }
140// else
141// {
142// m_value+=val.m_value;
143// (m_value<<=(64-N))>>=(64-N);
144// return (*this);
145// }
146
147 m_value+=val.m_value;
148 return (*this);
149 }
150
151 nmint<T> operator- (const nmint<T>& val) const
152 {
153 nmint<T> Res(*this);
154 Res-=val;
155 return Res;
156 }
157
158 nmint<T> operator+ (const nmint<T>& val) const
159 {
160 nmint<T> Res(*this);
161 Res+=val;
162 return Res;
163 }
164
165 void operator++ (int)
166 {
167 (*this)+=1;
168 }
169
170 void operator-- (int)
171 {
172 (*this)-=1;
173 }
174
175
176
177
178
179 nmint<T>& operator*= (const nmint<T>& val)
180 {
181 m_value*=val.m_value;
182 return (*this);
183 }
184
185 template <class T2> nmint<T2> operator* (const nmint<T2>& val) const
186 {
187 nmint<T2> Res;
188 Res.m_value=m_value*val.m_value;
189 return Res;
190 }
191
192
193 inline nmint<T>& operator/= (const nmint<T>& val)
194 {
195 m_value/=val.m_value;
196 }
197
198 inline nmint<T> operator/ (const nmint<T>& val) const
199 {
200 nmint<T> Res(*this);
201 Res/=val;
202 return Res;
203 }
204
205 inline nmint<T>& operator>>= (const int y)
206 {
207 m_value>>=y;
208 return (*this);
209 }
210
211 inline nmint<T> operator>> (const int y) const
212 {
213 nmint<T> z(*this);
214 z>>=y;
215 return z;
216 }
217
218 inline nmint<T>& operator<<= (const int y)
219 {
220 m_value<<=y;
221 return (*this);
222 }
223
224 inline nmint<T> operator<< (const int n) const
225 {
226 nmint<T> Res(*this);
227 Res<<=n;
228 return Res;
229 }
230
231 inline nmint<T>& operator^= (nmint<T> &val)
232 {
233 m_value^=val.m_value;
234 return (*this);
235 }
236 inline nmint<T> operator^ (nmint<T> &val) const
237 {
238 nmint<T> Res(*this);
239 Res^=val;
240 return Res;
241 }
242
243 nmint<T> operator- () const
244 {
245 nmint<T> Res;
246 Res.m_value=-m_value;
247 return Res;
248 }
249
250 bool operator> (const nmint<T>& y) const
251 { return m_value>y.m_value;}
252 bool operator>= (const nmint<T>& y) const
253 { return m_value>=y.m_value;}
254 bool operator< (const nmint<T>& y) const
255 { return m_value<y.m_value;}
256 bool operator<= (const nmint<T>& y) const
257 { return m_value<=y.m_value;}
258 bool operator== (const nmint<T>& y) const
259 { return m_value==y.m_value;}
260 bool operator!= (const nmint<T>& y) const
261 { return m_value!=y.m_value;}
262};
263
264
265
266/*
267
268template <int N> void Round(double& X,nmint<T> &Y)
269{
270 Y=X+0.5;
271}
272
273
274
276// Conversion of to different types
277template<int N> inline double double_(const nmint<T> &x)
278{
279 return double(x.m_value);
280}
281
282template<int N> inline int int_(const nmint<T> &x)
283{
284 return int(x.m_value);
285}
286template<int N> inline short int shortint_(const nmint<T> &x)
287{
288 return short int(x.m_value);
289}
290*/
291
292#ifdef __NM__
293#else
294typedef nmint<char> nmint8s;
295typedef nmint<short> nmint16s;
296#endif
297
298typedef nmint<int> nmint32s;
299typedef nmint<long long> nmint64s;
300
301#endif
302
303#endif
__INLINE__ ostream & operator<<(ostream &s, mtr< unsigned char > &mtr)
Definition: nmtlio.h:64