Changeset f9aada in git


Ignore:
Timestamp:
Aug 6, 2001, 2:50:50 PM (22 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
Children:
c794a95c85e7ae1437369ab150d85b7c4ff17fd0
Parents:
b87513c30ef67e4ec83bdb49804f182f9903f736
Message:
*hannes: simplified GMPrat


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

Legend:

Unmodified
Added
Removed
  • Singular/GMPrat.cc

    rb87513c rf9aada  
    3131//  Miscellaneous
    3232// ----------------------------------------------------------------------------
    33 extern int mmInit();
    34 static int GMPIsInitialized=mmInit();
    3533
    3634Rational Rational::save;    // dummy variable
    37 Rational RAT_EPS("1e-15");  // epsilon used in transcendental functions
    38 
    39 // ----------------------------------------------------------------------------
    40 //  the number Pi up to 25, 50, 75 and 100 digits
    41 // ----------------------------------------------------------------------------
    42 
    43 //Rational RAT_PI_25("3.141592653589793238462643");
    44 //Rational RAT_PI_50("3.1415926535897932384626433832795028841971693993751");
    45 //Rational RAT_PI_75("3.141592653589793238462643383279502884197169399375105820974944592307816406286");
    46 //Rational RAT_PI_100("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068");
    47 //Rational RAT_PI(RAT_PI_25);
    48 
    4935
    5036// ----------------------------------------------------------------------------
     
    10288    mpq_init( p->rat );
    10389    mpq_set_ui( p->rat,(unsigned long)a,1 );
    104 }
    105 
    106 Rational::Rational( short int a )
    107 {
    108     p = new rep;
    109     mpq_init( p->rat );
    110     mpq_set_si( p->rat,(long int)a,1 );
    111 }
    112 
    113 Rational::Rational( unsigned short int a )
    114 {
    115     p = new rep;
    116     mpq_init( p->rat );
    117     mpq_set_ui( p->rat,(unsigned long int)a,1 );
    118 }
    119 
    120 Rational::Rational( char a )
    121 {
    122     p = new rep;
    123     mpq_init( p->rat );
    124     mpq_set_si( p->rat,(long int)a,1 );
    125 }
    126 
    127 Rational::Rational( unsigned char a )
    128 {
    129     p = new rep;
    130     mpq_init( p->rat );
    131     mpq_set_ui( p->rat,(unsigned long int)a,1 );
    13290}
    13391
     
    283241}
    284242
    285 Rational::Rational(short int a, unsigned short int b)
    286 {
    287     p=new rep;
    288     mpq_init(p->rat);
    289     mpq_set_si(p->rat,(long int) a,(unsigned long int) b);
    290     mpq_canonicalize(p->rat);
    291 }
    292 
    293 Rational::Rational(unsigned short int a, unsigned short int b)
    294 {
    295     p=new rep;
    296     mpq_init(p->rat);
    297     mpq_set_ui(p->rat,(unsigned long int) a,(unsigned long int) b);
    298     mpq_canonicalize(p->rat);
    299 }
    300 
    301 Rational::Rational(char a, unsigned char b)
    302 {
    303     p=new rep;
    304     mpq_init(p->rat);
    305     mpq_set_si(p->rat,(long int) a,(unsigned long int) b);
    306     mpq_canonicalize(p->rat);
    307 }
    308 
    309 Rational::Rational(unsigned char a, unsigned char b)
    310 {
    311     p=new rep;
    312     mpq_init(p->rat);
    313     mpq_set_ui(p->rat,(unsigned long int) a,(unsigned long int) b);
    314     mpq_canonicalize(p->rat);
    315 }
    316 
    317243Rational::Rational(const Rational& a, const Rational& b)
    318244{
     
    340266}
    341267
    342 Rational::Rational(short int a, short int b)
    343 {
    344     if (b<0) a=-a;
    345     p=new rep;
    346     mpq_init(p->rat);
    347     mpq_set_si(p->rat,(long int) a,(unsigned long int) abs(b));
    348     mpq_canonicalize(p->rat);
    349 }
    350 
    351 Rational::Rational(char a, char b)
    352 {
    353     if (b<0) a=-a;
    354     p=new rep;
    355     mpq_init(p->rat);
    356     mpq_set_si(p->rat,(long int) a,(unsigned long int) abs(b));
    357     mpq_canonicalize(p->rat);
    358 }
    359 
    360268Rational::Rational(char *sn, char *sd)
    361269{
     
    384292//  Assignment operators
    385293// ----------------------------------------------------------------------------
    386 
    387 Rational& Rational::operator=(long int a)
    388 {
    389   disconnect();
    390   mpq_set_si(p->rat,a,1);
    391   return *this;
    392 }
    393 
    394 Rational& Rational::operator=(unsigned long int a)
    395 {
    396   disconnect();
    397   mpq_set_ui(p->rat,a,1);
    398   return *this;
    399 }
    400 
    401294Rational& Rational::operator=(int a)
    402295{
    403296  disconnect();
    404297  mpq_set_si(p->rat,(long int) a,1);
    405   return *this;
    406 }
    407 
    408 Rational& Rational::operator=(unsigned int a)
    409 {
    410   disconnect();
    411   mpq_set_ui(p->rat,(unsigned long int) a,1);
    412   return *this;
    413 }
    414 
    415 Rational& Rational::operator=(short int a)
    416 {
    417   disconnect();
    418   mpq_set_si(p->rat,(long int) a,1);
    419   return *this;
    420 }
    421 
    422 Rational& Rational::operator=(unsigned short int a)
    423 {
    424   disconnect();
    425   mpq_set_ui(p->rat,(unsigned long int) a,1);
    426   return *this;
    427 }
    428 
    429 Rational& Rational::operator=(char a)
    430 {
    431   disconnect();
    432   mpq_set_si(p->rat,(long int) a,1);
    433   return *this;
    434 }
    435 
    436 Rational& Rational::operator=(unsigned char a)
    437 {
    438   disconnect();
    439   mpq_set_ui(p->rat,(unsigned long int) a,1);
    440298  return *this;
    441299}
     
    1014872}
    1015873
    1016 Rational
    1017 sqrt(const Rational& a)
    1018 {
    1019   Rational
    1020     erg;
    1021   mpz_t
    1022     h1,
    1023     h2;
    1024 
    1025   mpz_init_set(h1,mpq_numref(a.p->rat));
    1026   mpz_init(h2);
    1027   mpz_set_ui(h2,1);
    1028   mpz_mul(h1,h1,mpq_denref(a.p->rat));
    1029   mpz_mul(h1,h1,mpq_denref(RAT_EPS.p->rat));
    1030   mpz_mul(h1,h1,mpq_denref(RAT_EPS.p->rat));
    1031   mpz_div(h1,h1,mpq_numref(RAT_EPS.p->rat));
    1032   mpz_div(h1,h1,mpq_numref(RAT_EPS.p->rat));
    1033   mpz_sqrt(h1,h1);
    1034   mpz_mul(h2,mpq_denref(a.p->rat),mpq_denref(RAT_EPS.p->rat));
    1035   mpz_div(h2,h2,mpq_numref(RAT_EPS.p->rat));
    1036   mpq_set_num(erg.p->rat,h1);
    1037   mpq_set_den(erg.p->rat,h2);
    1038   mpq_canonicalize(erg.p->rat);
    1039   mpz_clear(h1);
    1040   mpz_clear(h2);
    1041   return erg;
    1042 }
    1043 
    1044 Rational
    1045 exp(const Rational& a)
    1046 {
    1047   Rational
    1048     erg(1),
    1049     pow(a),
    1050     fak(1),
    1051     rem,
    1052     i(2);
    1053 
    1054   do{
    1055     erg+=pow/fak;
    1056     fak*=i++;
    1057     pow*=a;
    1058     rem=(((Rational)2)*abs(pow))/fak;
    1059     if (rem<RAT_EPS) break;
    1060   } while (true);
    1061   return erg;
    1062 }
    1063 
    1064 Rational
    1065 sin(const Rational& a)
    1066 {
    1067   Rational
    1068     erg(a),
    1069     pow(a),
    1070     fak(6),
    1071     rem,
    1072     i(4),
    1073     aq(a);
    1074 
    1075   aq*=a;
    1076   do {
    1077     pow*=-aq;
    1078     erg+=pow/fak;
    1079     fak*=i++;
    1080     fak*=i++;
    1081     rem=(abs(pow*aq))/fak;
    1082     if (rem<RAT_EPS) break;
    1083   } while(true);
    1084   return erg;
    1085 }
    1086 
    1087 Rational
    1088 cos(const Rational& a)
    1089 {
    1090   Rational
    1091     erg(1),
    1092     pow(1),
    1093     fak(2),
    1094     rem,
    1095     i(3),
    1096     aq(a);
    1097 
    1098   aq*=a;
    1099   do {
    1100     pow*=-aq;
    1101     erg+=pow/fak;
    1102     fak*=i++;
    1103     fak*=i++;
    1104     rem=(abs(pow*aq))/fak;
    1105     if (rem<RAT_EPS) break;
    1106   } while(true);
    1107   return erg;
    1108 }
    1109 
    1110 Rational
    1111 tan(const Rational& a)
    1112 {
    1113   Rational
    1114     ergsin(a),
    1115     ergcos(1),
    1116     pow(a),
    1117     fak(2),
    1118     i(3),
    1119     rem,
    1120     eps2(((Rational)2)*RAT_EPS);
    1121 
    1122   do{
    1123     pow*=a*(-1);
    1124     ergcos+=pow/fak;
    1125     pow*=a;
    1126     fak*=i++;
    1127     ergsin+=pow/fak;
    1128     fak*=i++;
    1129     rem=(abs(pow*a*a))/fak;
    1130     if (rem<eps2) break;
    1131   } while(true);
    1132   return ergsin/ergcos;
    1133 }
    1134 
    1135874Rational gcd( const Rational &a,const Rational &b )
    1136875{
  • Singular/GMPrat.h

    rb87513c rf9aada  
    3333    Rational( int );
    3434    Rational( unsigned int );
    35     Rational( short int );
    36     Rational( unsigned short int );
    37     Rational( char );
    38     Rational( unsigned char );
    3935    Rational( double );
    4036    Rational( float );
     
    4541    Rational( int, unsigned int );
    4642    Rational( unsigned int,unsigned int );
    47     Rational( short int,unsigned short int );
    48     Rational( unsigned short int,unsigned short int );
    49     Rational( char,unsigned char );
    50     Rational( unsigned char,unsigned char );
    5143    Rational( const Rational&,const Rational& );
    5244    Rational( long int,long int );
    5345    Rational( int,int );
    54     Rational( short int,short int );
    55     Rational( char,char );
    5646    Rational( char*,char* );
    5747    ~Rational( );
    5848
    59     Rational& operator = ( long int );
    60     Rational& operator = ( unsigned long int );
    6149    Rational& operator = ( int );
    62     Rational& operator = ( unsigned int );
    63     Rational& operator = ( short int );
    64     Rational& operator = ( unsigned short int );
    65     Rational& operator = ( char );
    66     Rational& operator = ( unsigned char );
    6750    Rational& operator = ( double );
    6851    Rational& operator = ( float );
     
    11396    friend int      sgn ( const Rational& );
    11497    friend Rational abs ( const Rational& );
    115     friend Rational sqrt( const Rational& );
    11698    friend Rational pow ( const Rational&,int );
    11799
     
    129111Rational operator / ( const Rational&, const Rational& );
    130112
    131 Rational exp( const Rational& );
    132 Rational sin( const Rational& );
    133 Rational cos( const Rational& );
    134 Rational tan( const Rational& );
    135 
    136113#endif /* GMPRAT_H */
    137114
Note: See TracChangeset for help on using the changeset viewer.