Changeset 5f6e18 in git for IntegerProgramming


Ignore:
Timestamp:
Jan 26, 2010, 12:19:30 PM (14 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '4a9821a93ffdc22a6696668bd4f6b8c9de3e6c5f')
Children:
4c4a8025d5593bc6f5fd2950cfac144eb2d79cd3
Parents:
b08831b5ca1d5599093809e7c98515d0ceef5423
Message:
BigInt simplified

git-svn-id: file:///usr/local/Singular/svn/trunk@12458 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
IntegerProgramming
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • IntegerProgramming/BigInt.cc

    rb08831 r5f6e18  
    1717}
    1818
    19 BigInt::BigInt(long int a)
     19BigInt::BigInt(int a)
    2020{
    2121  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);
    6523}
    6624
     
    8341//
    8442
    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 
    9743BigInt& BigInt::operator=(int a)
    9844{
    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);
    13046  return *this;
    13147}
     
    14763}
    14864
    149 BigInt::operator long int()
     65BigInt::operator int()
    15066{
    15167  long int ret_val;
    15268  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
     72BigInt::operator short()
    15773{
    15874  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;
    19777}
    19878
     
    326206}
    327207
    328 bool operator<(const long int& a,const BigInt& b)
     208bool operator<(const int& a,const BigInt& b)
    329209{
    330210  if (mpz_cmp(BigInt(a).value,b.value)<0) return true;
     
    332212}
    333213
    334 bool operator<=(const long int& a,const BigInt& b)
     214bool operator<=(const int& a,const BigInt& b)
    335215{
    336216  if (mpz_cmp(BigInt(a).value,b.value)>0) return false;
     
    338218}
    339219
    340 bool operator>(const long int& a,const BigInt& b)
     220bool operator>(const int& a,const BigInt& b)
    341221{
    342222  if (mpz_cmp(BigInt(a).value,b.value)>0) return true;
     
    344224}
    345225
    346 bool operator>=(const long int& a,const BigInt& b)
     226bool operator>=(const int& a,const BigInt& b)
    347227{
    348228  if (mpz_cmp(BigInt(a).value,b.value)<0) return false;
     
    350230}
    351231
    352 bool operator==(const long int& a,const BigInt& b)
     232bool operator==(const int& a,const BigInt& b)
    353233{
    354234  if (!mpz_cmp(BigInt(a).value,b.value)) return true;
     
    356236}
    357237
    358 bool operator!=(const long int& a,const BigInt& b)
     238bool operator!=(const int& a,const BigInt& b)
    359239{
    360240  if (!mpz_cmp(BigInt(a).value,b.value)) return false;
     
    362242}
    363243
    364 bool operator<(const BigInt& a,const long int& b)
     244bool operator<(const BigInt& a,const int& b)
    365245{
    366246  if (mpz_cmp(a.value,BigInt(b).value)<0) return true;
     
    368248}
    369249
    370 bool operator<=(const BigInt& a,const long int& b)
     250bool operator<=(const BigInt& a,const int& b)
    371251{
    372252  if (mpz_cmp(a.value,BigInt(b).value)>0) return false;
     
    374254}
    375255
    376 bool operator>(const BigInt& a,const long int& b)
     256bool operator>(const BigInt& a,const int& b)
    377257{
    378258  if (mpz_cmp(a.value,BigInt(b).value)>0) return true;
     
    380260}
    381261
    382 bool operator>=(const BigInt& a,const long int& b)
     262bool operator>=(const BigInt& a,const int& b)
    383263{
    384264  if (mpz_cmp(a.value,BigInt(b).value)<0) return false;
     
    386266}
    387267
    388 bool operator==(const BigInt& a,const long int& b)
     268bool operator==(const BigInt& a,const int& b)
    389269{
    390270  if (!mpz_cmp(a.value,BigInt(b).value)) return true;
     
    392272}
    393273
    394 bool operator!=(const BigInt& a,const long int& b)
     274bool operator!=(const BigInt& a,const int& b)
    395275{
    396276  if (!mpz_cmp(a.value,BigInt(b).value)) return false;
     
    426306}
    427307
    428 BigInt operator+(const long int& a,const BigInt &b)
     308BigInt operator+(const int& a,const BigInt &b)
    429309{
    430310  BigInt erg(a);
     
    432312}
    433313
    434 BigInt operator-(const long int& a,const BigInt &b)
     314BigInt operator-(const int& a,const BigInt &b)
    435315{
    436316  BigInt erg(a);
     
    438318}
    439319
    440 BigInt operator*(const long int& a,const BigInt &b)
     320BigInt operator*(const int& a,const BigInt &b)
    441321{
    442322  BigInt erg(a);
     
    444324}
    445325
    446 BigInt operator/(const long int& a,const BigInt &b)
     326BigInt operator/(const int& a,const BigInt &b)
    447327{
    448328  BigInt erg(a);
     
    450330}
    451331
    452 BigInt operator+(const BigInt& a,const long int &b)
     332BigInt operator+(const BigInt& a,const int &b)
    453333{
    454334  BigInt erg(a);
     
    456336}
    457337
    458 BigInt operator-(const BigInt& a,const long int &b)
     338BigInt operator-(const BigInt& a,const int &b)
    459339{
    460340  BigInt erg(a);
     
    462342}
    463343
    464 BigInt operator*(const BigInt& a,const long int &b)
     344BigInt operator*(const BigInt& a,const int &b)
    465345{
    466346  BigInt erg(a);
     
    468348}
    469349
    470 BigInt operator/(const BigInt& a,const long int &b)
     350BigInt operator/(const BigInt& a,const int &b)
    471351{
    472352  BigInt erg(a);
  • IntegerProgramming/BigInt.h

    rb08831 r5f6e18  
    2121
    2222    BigInt( );
    23     BigInt( long int );
    24     BigInt( unsigned long int );
    2523    BigInt( int );
    26     BigInt( unsigned int );
    27     BigInt( short int );
    28     BigInt( unsigned short int );
    29     BigInt( char );
    30     BigInt( unsigned char );
    3124    BigInt( const BigInt& );
    3225    ~BigInt( );
    3326
    34     BigInt& operator = ( long int );
    35     BigInt& operator = ( unsigned long int );
    3627    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 );
    4228    BigInt& operator = ( const BigInt& );
    4329
    4430    operator bool( );
    45     operator long int( );
    46     operator unsigned long int( );
    4731    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( );
    5333
    5434    BigInt  operator - ( );
     
    7050    friend bool operator == ( const BigInt&, const BigInt& );
    7151    friend bool operator != ( const BigInt&, const BigInt& );
    72     friend bool operator <  ( const long int&, const BigInt& );
    73     friend bool operator <= ( const long int&, const BigInt& );
    74     friend bool operator >  ( const long int&, const BigInt& );
    75     friend bool operator >= ( const long int&, const BigInt& );
    76     friend bool operator == ( const long int&, const BigInt& );
    77     friend bool operator != ( const long int&, const BigInt& );
    78     friend bool operator <  ( const BigInt&, const long int& );
    79     friend bool operator <= ( const BigInt&, const long int& );
    80     friend bool operator >  ( const BigInt&, const long int& );
    81     friend bool operator >= ( const BigInt&, const long int& );
    82     friend bool operator == ( const BigInt&, const long int& );
    83     friend bool operator != ( const BigInt&, const long int& );
     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& );
    8464 
    8565    friend int    sgn ( const BigInt& );
     
    9171BigInt operator * ( const BigInt&, const BigInt& );
    9272BigInt operator / ( const BigInt&, const BigInt& );
    93 BigInt operator + ( const long int&, const BigInt& );
    94 BigInt operator - ( const long int&, const BigInt& );
    95 BigInt operator * ( const long int&, const BigInt& );
    96 BigInt operator / ( const long int&, const BigInt& );
    97 BigInt operator + ( const BigInt&, const long int& );
    98 BigInt operator - ( const BigInt&, const long int& );
    99 BigInt operator * ( const BigInt&, const long int& );
    100 BigInt operator / ( const BigInt&, const long int& );
     73BigInt operator + ( const int&, const BigInt& );
     74BigInt operator - ( const int&, const BigInt& );
     75BigInt operator * ( const int&, const BigInt& );
     76BigInt operator / ( const int&, const BigInt& );
     77BigInt operator + ( const BigInt&, const int& );
     78BigInt operator - ( const BigInt&, const int& );
     79BigInt operator * ( const BigInt&, const int& );
     80BigInt operator / ( const BigInt&, const int& );
    10181
    10282#endif  // BIG_INT_H
Note: See TracChangeset for help on using the changeset viewer.