|
|
1.1 ! root 1: ! 2: #include <stream.h> ! 3: #include <errno.h> ! 4: ! 5: overload cos; ! 6: overload cosh; ! 7: overload exp; ! 8: overload log; ! 9: overload pow; ! 10: overload sin; ! 11: overload sinh; ! 12: overload sqrt; ! 13: overload abs; ! 14: ! 15: #include <math.h> ! 16: inline double abs(double d) { return fabs(d); } ! 17: ! 18: class complex { ! 19: double re, im; ! 20: public: ! 21: complex(double r, double i) { re=r; im=i; } ! 22: complex(double r) { re=r; im=0; } ! 23: complex() { re=0; im=0; } ! 24: ! 25: friend double real(const complex& a ) { return a.re; } ! 26: friend double imag(const complex& a ) { return a.im; } ! 27: ! 28: friend double abs(complex); ! 29: friend double norm(complex); ! 30: friend double arg(complex); ! 31: friend complex conj(complex a) { return complex(a.re, -a.im); } ! 32: friend complex cos(complex); ! 33: friend complex cosh(complex); ! 34: friend complex exp(complex); ! 35: friend complex log(complex); ! 36: friend complex pow(double, complex); ! 37: friend complex pow(complex, int); ! 38: friend complex pow(complex, double); ! 39: friend complex pow(complex, complex); ! 40: friend complex polar(double, double = 0); ! 41: friend complex sin(complex); ! 42: friend complex sinh(complex); ! 43: friend complex sqrt(complex); ! 44: ! 45: friend complex operator+(complex a1, complex a2) ! 46: { ! 47: return complex(a1.re+a2.re, a1.im+a2.im); ! 48: } ! 49: friend complex operator-(complex a1, complex a2) ! 50: { ! 51: return complex(a1.re-a2.re, a1.im-a2.im); ! 52: } ! 53: friend complex operator-(complex a) { return complex(-a.re, -a.im); } ! 54: friend complex operator*(complex, complex); ! 55: friend complex operator/(complex, complex); ! 56: friend int operator==(complex a, complex b) ! 57: { ! 58: return a.re==b.re && a.im==b.im; ! 59: } ! 60: friend int operator!=(complex a, complex b) ! 61: { ! 62: return a.re!=b.re || a.im!=b.im; ! 63: } ! 64: friend int operator==(complex, complex); ! 65: friend int operator!=(complex, complex); ! 66: ! 67: void operator+=(complex a) { re += a.re; im += a.im; } ! 68: void operator-=(complex a) { re -= a.re; im -= a.im; } ! 69: void operator*=(complex); ! 70: void operator/=(complex); ! 71: }; ! 72: ! 73: ostream& operator<<(ostream&, complex); ! 74: istream& operator>>(istream&, complex&); ! 75: ! 76: void complex_error(int,double); ! 77: extern int errno; ! 78:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.