Changeset 5f6e18 in git
- Timestamp:
- Jan 26, 2010, 12:19:30 PM (13 years ago)
- Branches:
- (u'spielwiese', 'f6c3dc58b0df4bd712574325fe76d0626174ad97')
- Children:
- 4c4a8025d5593bc6f5fd2950cfac144eb2d79cd3
- Parents:
- b08831b5ca1d5599093809e7c98515d0ceef5423
- Location:
- IntegerProgramming
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
IntegerProgramming/BigInt.cc
rb08831 r5f6e18 17 17 } 18 18 19 BigInt::BigInt( longint a)19 BigInt::BigInt(int a) 20 20 { 21 21 mpz_init(value); 22 mpz_set_si(value,a); 23 } 24 25 BigInt::BigInt(unsigned long int a) 26 { 27 mpz_init(value); 28 mpz_set_ui(value,a); 29 } 30 31 BigInt::BigInt(int a) 32 { 33 mpz_init(value); 34 mpz_set_si(value,(long int)a); 35 } 36 37 BigInt::BigInt(unsigned int a) 38 { 39 mpz_init(value); 40 mpz_set_ui(value,(unsigned long)a); 41 } 42 43 BigInt::BigInt(short int a) 44 { 45 mpz_init(value); 46 mpz_set_si(value,(long int)a); 47 } 48 49 BigInt::BigInt(unsigned short int a) 50 { 51 mpz_init(value); 52 mpz_set_ui(value,(unsigned long int)a); 53 } 54 55 BigInt::BigInt(char a) 56 { 57 mpz_init(value); 58 mpz_set_si(value,(long int)a); 59 } 60 61 BigInt::BigInt(unsigned char a) 62 { 63 mpz_init(value); 64 mpz_set_ui(value,(unsigned long int)a); 22 mpz_set_si(value,(long)a); 65 23 } 66 24 … … 83 41 // 84 42 85 BigInt& BigInt::operator=(long int a)86 {87 mpz_set_si(value,a);88 return *this;89 }90 91 BigInt& BigInt::operator=(unsigned long int a)92 {93 mpz_set_ui(value,a);94 return *this;95 }96 97 43 BigInt& BigInt::operator=(int a) 98 44 { 99 mpz_set_si(value,(long int) a); 100 return *this; 101 } 102 103 BigInt& BigInt::operator=(unsigned int a) 104 { 105 mpz_set_ui(value,(unsigned long int) a); 106 return *this; 107 } 108 109 BigInt& BigInt::operator=(short int a) 110 { 111 mpz_set_si(value,(long int) a); 112 return *this; 113 } 114 115 BigInt& BigInt::operator=(unsigned short int a) 116 { 117 mpz_set_ui(value,(unsigned long int) a); 118 return *this; 119 } 120 121 BigInt& BigInt::operator=(char a) 122 { 123 mpz_set_si(value,(long int) a); 124 return *this; 125 } 126 127 BigInt& BigInt::operator=(unsigned char a) 128 { 129 mpz_set_ui(value,(unsigned long int) a); 45 mpz_set_si(value,(long)a); 130 46 return *this; 131 47 } … … 147 63 } 148 64 149 BigInt::operator longint()65 BigInt::operator int() 150 66 { 151 67 long int ret_val; 152 68 ret_val=mpz_get_si(value); 153 return ret_val;154 } 155 156 BigInt::operator unsigned long int()69 return (int)ret_val; 70 } 71 72 BigInt::operator short() 157 73 { 158 74 long int ret_val; 159 ret_val=mpz_get_ui(value); 160 return ret_val; 161 } 162 163 BigInt::operator int() 164 { 165 int ret_val=operator long int(); 166 return ret_val; 167 } 168 169 BigInt::operator unsigned int() 170 { 171 unsigned int ret_val=operator unsigned long int(); 172 return ret_val; 173 } 174 175 BigInt::operator short int() 176 { 177 short int ret_val=operator long int(); 178 return ret_val; 179 } 180 181 BigInt::operator unsigned short int() 182 { 183 unsigned short int ret_val=operator unsigned long int(); 184 return ret_val; 185 } 186 187 BigInt::operator char() 188 { 189 char ret_val=operator long int(); 190 return ret_val; 191 } 192 193 BigInt::operator unsigned char() 194 { 195 unsigned char ret_val=operator unsigned long int(); 196 return ret_val; 75 ret_val=mpz_get_si(value); 76 return (short)ret_val; 197 77 } 198 78 … … 326 206 } 327 207 328 bool operator<(const longint& a,const BigInt& b)208 bool operator<(const int& a,const BigInt& b) 329 209 { 330 210 if (mpz_cmp(BigInt(a).value,b.value)<0) return true; … … 332 212 } 333 213 334 bool operator<=(const longint& a,const BigInt& b)214 bool operator<=(const int& a,const BigInt& b) 335 215 { 336 216 if (mpz_cmp(BigInt(a).value,b.value)>0) return false; … … 338 218 } 339 219 340 bool operator>(const longint& a,const BigInt& b)220 bool operator>(const int& a,const BigInt& b) 341 221 { 342 222 if (mpz_cmp(BigInt(a).value,b.value)>0) return true; … … 344 224 } 345 225 346 bool operator>=(const longint& a,const BigInt& b)226 bool operator>=(const int& a,const BigInt& b) 347 227 { 348 228 if (mpz_cmp(BigInt(a).value,b.value)<0) return false; … … 350 230 } 351 231 352 bool operator==(const longint& a,const BigInt& b)232 bool operator==(const int& a,const BigInt& b) 353 233 { 354 234 if (!mpz_cmp(BigInt(a).value,b.value)) return true; … … 356 236 } 357 237 358 bool operator!=(const longint& a,const BigInt& b)238 bool operator!=(const int& a,const BigInt& b) 359 239 { 360 240 if (!mpz_cmp(BigInt(a).value,b.value)) return false; … … 362 242 } 363 243 364 bool operator<(const BigInt& a,const longint& b)244 bool operator<(const BigInt& a,const int& b) 365 245 { 366 246 if (mpz_cmp(a.value,BigInt(b).value)<0) return true; … … 368 248 } 369 249 370 bool operator<=(const BigInt& a,const longint& b)250 bool operator<=(const BigInt& a,const int& b) 371 251 { 372 252 if (mpz_cmp(a.value,BigInt(b).value)>0) return false; … … 374 254 } 375 255 376 bool operator>(const BigInt& a,const longint& b)256 bool operator>(const BigInt& a,const int& b) 377 257 { 378 258 if (mpz_cmp(a.value,BigInt(b).value)>0) return true; … … 380 260 } 381 261 382 bool operator>=(const BigInt& a,const longint& b)262 bool operator>=(const BigInt& a,const int& b) 383 263 { 384 264 if (mpz_cmp(a.value,BigInt(b).value)<0) return false; … … 386 266 } 387 267 388 bool operator==(const BigInt& a,const longint& b)268 bool operator==(const BigInt& a,const int& b) 389 269 { 390 270 if (!mpz_cmp(a.value,BigInt(b).value)) return true; … … 392 272 } 393 273 394 bool operator!=(const BigInt& a,const longint& b)274 bool operator!=(const BigInt& a,const int& b) 395 275 { 396 276 if (!mpz_cmp(a.value,BigInt(b).value)) return false; … … 426 306 } 427 307 428 BigInt operator+(const longint& a,const BigInt &b)308 BigInt operator+(const int& a,const BigInt &b) 429 309 { 430 310 BigInt erg(a); … … 432 312 } 433 313 434 BigInt operator-(const longint& a,const BigInt &b)314 BigInt operator-(const int& a,const BigInt &b) 435 315 { 436 316 BigInt erg(a); … … 438 318 } 439 319 440 BigInt operator*(const longint& a,const BigInt &b)320 BigInt operator*(const int& a,const BigInt &b) 441 321 { 442 322 BigInt erg(a); … … 444 324 } 445 325 446 BigInt operator/(const longint& a,const BigInt &b)326 BigInt operator/(const int& a,const BigInt &b) 447 327 { 448 328 BigInt erg(a); … … 450 330 } 451 331 452 BigInt operator+(const BigInt& a,const longint &b)332 BigInt operator+(const BigInt& a,const int &b) 453 333 { 454 334 BigInt erg(a); … … 456 336 } 457 337 458 BigInt operator-(const BigInt& a,const longint &b)338 BigInt operator-(const BigInt& a,const int &b) 459 339 { 460 340 BigInt erg(a); … … 462 342 } 463 343 464 BigInt operator*(const BigInt& a,const longint &b)344 BigInt operator*(const BigInt& a,const int &b) 465 345 { 466 346 BigInt erg(a); … … 468 348 } 469 349 470 BigInt operator/(const BigInt& a,const longint &b)350 BigInt operator/(const BigInt& a,const int &b) 471 351 { 472 352 BigInt erg(a); -
IntegerProgramming/BigInt.h
rb08831 r5f6e18 21 21 22 22 BigInt( ); 23 BigInt( long int );24 BigInt( unsigned long int );25 23 BigInt( int ); 26 BigInt( unsigned int );27 BigInt( short int );28 BigInt( unsigned short int );29 BigInt( char );30 BigInt( unsigned char );31 24 BigInt( const BigInt& ); 32 25 ~BigInt( ); 33 26 34 BigInt& operator = ( long int );35 BigInt& operator = ( unsigned long int );36 27 BigInt& operator = ( int ); 37 BigInt& operator = ( unsigned int );38 BigInt& operator = ( short int );39 BigInt& operator = ( unsigned short int );40 BigInt& operator = ( char );41 BigInt& operator = ( unsigned char );42 28 BigInt& operator = ( const BigInt& ); 43 29 44 30 operator bool( ); 45 operator long int( );46 operator unsigned long int( );47 31 operator int( ); 48 operator unsigned int( ); 49 operator short int( ); 50 operator unsigned short int( ); 51 operator char( ); 52 operator unsigned char( ); 32 operator short( ); 53 33 54 34 BigInt operator - ( ); … … 70 50 friend bool operator == ( const BigInt&, const BigInt& ); 71 51 friend bool operator != ( const BigInt&, const BigInt& ); 72 friend bool operator < ( const longint&, const BigInt& );73 friend bool operator <= ( const longint&, const BigInt& );74 friend bool operator > ( const longint&, const BigInt& );75 friend bool operator >= ( const longint&, const BigInt& );76 friend bool operator == ( const longint&, const BigInt& );77 friend bool operator != ( const longint&, const BigInt& );78 friend bool operator < ( const BigInt&, const longint& );79 friend bool operator <= ( const BigInt&, const longint& );80 friend bool operator > ( const BigInt&, const longint& );81 friend bool operator >= ( const BigInt&, const longint& );82 friend bool operator == ( const BigInt&, const longint& );83 friend bool operator != ( const BigInt&, const longint& );52 friend bool operator < ( const int&, const BigInt& ); 53 friend bool operator <= ( const int&, const BigInt& ); 54 friend bool operator > ( const int&, const BigInt& ); 55 friend bool operator >= ( const int&, const BigInt& ); 56 friend bool operator == ( const int&, const BigInt& ); 57 friend bool operator != ( const int&, const BigInt& ); 58 friend bool operator < ( const BigInt&, const int& ); 59 friend bool operator <= ( const BigInt&, const int& ); 60 friend bool operator > ( const BigInt&, const int& ); 61 friend bool operator >= ( const BigInt&, const int& ); 62 friend bool operator == ( const BigInt&, const int& ); 63 friend bool operator != ( const BigInt&, const int& ); 84 64 85 65 friend int sgn ( const BigInt& ); … … 91 71 BigInt operator * ( const BigInt&, const BigInt& ); 92 72 BigInt operator / ( const BigInt&, const BigInt& ); 93 BigInt operator + ( const longint&, const BigInt& );94 BigInt operator - ( const longint&, const BigInt& );95 BigInt operator * ( const longint&, const BigInt& );96 BigInt operator / ( const longint&, const BigInt& );97 BigInt operator + ( const BigInt&, const longint& );98 BigInt operator - ( const BigInt&, const longint& );99 BigInt operator * ( const BigInt&, const longint& );100 BigInt operator / ( const BigInt&, const longint& );73 BigInt operator + ( const int&, const BigInt& ); 74 BigInt operator - ( const int&, const BigInt& ); 75 BigInt operator * ( const int&, const BigInt& ); 76 BigInt operator / ( const int&, const BigInt& ); 77 BigInt operator + ( const BigInt&, const int& ); 78 BigInt operator - ( const BigInt&, const int& ); 79 BigInt operator * ( const BigInt&, const int& ); 80 BigInt operator / ( const BigInt&, const int& ); 101 81 102 82 #endif // BIG_INT_H
Note: See TracChangeset
for help on using the changeset viewer.