complex.h
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 455 行 · 第 1/2 页
H
455 行
}
// modulus -- Return the magnitude or norm of Complex vector
inline double CoolComplex::modulus () const {
return sqrt((this->r * this->r) + (this->i * this->i));
}
// argument -- Return the angle from x-axis to Complex vector
inline double CoolComplex::argument () const {
return atan2(this->i, this->r);
}
// operator== -- Overload the equality operator for the CoolComplex class
// Input: Reference to CoolComplex object
// Output: TRUE/FALSE
inline Boolean CoolComplex::operator== (const CoolComplex& c) const {
return (this->r == c.r && this->i == c.i);
}
// operator!= -- Overload the inequality operator for the CoolComplex class
// Input: Reference to a constant CoolComplex object
// Ouput: TRUE/FALSE
inline Boolean CoolComplex::operator!= (const CoolComplex& c) const {
return !(*this == c);
}
// operator<< -- Overload the output operator for a pointer to a CoolComplex
// Input: Ostream reference, pointer to a CoolComplex object
// Output: Ostream reference
inline ostream& operator<< (ostream& os, const CoolComplex* c) {
return operator<< (os, *c);
}
// invert -- Calculate the reciprical of a complex number
// Input: None
// Output: Reciprical of complex
inline CoolComplex CoolComplex::invert () const {
double normalize = (this->r * this->r)+(this->i * this->i);
return CoolComplex ((this->r / normalize), (-this->i / normalize));
}
// operator- -- Overload the unary minus operator for the CoolComplex class
// Input: None
// Output: Negated CoolComplex value
inline CoolComplex CoolComplex::operator- () const {
return CoolComplex (-this->r, -this->i); // Get negative value
}
// conjugate -- Provide conjugate (that is, negate imaginary part) of complex
// Input: None
// Output: Negated CoolComplex value
inline CoolComplex CoolComplex::conjugate () const {
return CoolComplex (this->r, -this->i); // Get negative value
}
// operator! -- Overload the negation operator for the CoolComplex class
// Input: None
// Output: TRUE/FALSE
inline Boolean CoolComplex::operator! () const {
return ((this->r == 0.0) ? TRUE : FALSE); // Return logical state
}
// operator++ -- Overload the increment operator for the CoolComplex class
// Input: None
// Output: Reference to updated CoolComplex object
inline CoolComplex& CoolComplex::operator++ () {
this->r++ ; // Increment real part
return *this; // Return updated object
}
// operator-- -- Overload the decrement operator for the CoolComplex class
// Input: None
// Output: Reference to updated CoolComplex object
inline CoolComplex& CoolComplex::operator-- () {
this->r--; // Decrement real part
return *this; // Return updated object
}
// operator+ -- Overload the addition operator for the CoolComplex class
// Input: Reference to complex object
// Output: Reference to new complex object
inline CoolComplex operator+ (const CoolComplex& c1, const CoolComplex& c2) {
return CoolComplex (c1.real()+c2.real(), c1.imaginary()+c2.imaginary());
}
// operator- -- Overload the subtraction operator for the CoolComplex class
// Input: Reference to CoolComplex object
// Output: Reference to new CoolComplex object
inline CoolComplex operator- (const CoolComplex& c1, const CoolComplex& c2) {
return CoolComplex (c1.real()-c2.real(), c1.imaginary()-c2.imaginary());
}
// operator* -- Overload the multiplication operator for the CoolComplex class
// Input: Reference to complex object
// Output: Reference to new complex object
inline CoolComplex operator* (const CoolComplex& c1, const CoolComplex& c2) {
return CoolComplex (((c1.r * c2.r)-(c1.i * c2.i)),
((c1.r * c2.i)+(c1.i * c2.r)));
}
// operator/ -- Overload the division operator for the CoolComplex class
// Input: Reference to complex object
// Output: Reference to new complex object
inline CoolComplex operator/ (const CoolComplex& c1, const CoolComplex& c2) {
CoolComplex result = c1;
result /= c2;
return result;
}
// operator+= -- Overload the addition/assign operator for the CoolComplex class
// Input: Reference to complex object
// Output: None
inline CoolComplex& CoolComplex::operator+= (const CoolComplex& c) {
this->r += c.r; // Add real part
this->i += c.i; // Add imaginary part
return *this;
}
// operator-= -- Overload the subtraction/assign operator for the CoolComplex class
// Input: Reference to complex object
// Output: None
inline CoolComplex& CoolComplex::operator-= (const CoolComplex& c) {
this->r -= c.r; // Subtract real part
this->i -= c.i; // Subtract imaginary part
return *this;
}
// operator*= -- Overload the multiplication/assign operator for CoolComplex class
// Input: Reference to complex object
// Output: None
inline CoolComplex& CoolComplex::operator*= (const CoolComplex& c) {
this->r = (this->r * c.r)-(this->i * c.i); // Multiply real part
this->i = (this->r * c.i)+(this->i * c.r); // Multiply imaginary part
return *this;
}
// sin -- Calculate the sine of a CoolComplex number
// Input: Reference to a complex
// Output: Reference to a new complex whose value is the answer
inline CoolComplex CoolComplex::sin () const {
return CoolComplex (::sin (this->r), ::sin (this->i));
}
// cos -- Calculate the cosine of a Complex number
// Input: Reference to a complex
// Output: Reference to a new complex whose value is the answer
inline CoolComplex CoolComplex::cos () const {
return CoolComplex (::cos (this->r), ::cos (this->i));
}
// tan -- Calculate the tangent of a CoolComplex number
// Input: Reference to a complex
// Output: Reference to a new complex whose value is the answer
inline CoolComplex CoolComplex::tan () const {
return CoolComplex (::tan (this->r), ::tan (this->i));
}
// sinh -- Calculate the hyperbolic sine of a CoolComplex number
// Input: Reference to a complex
// Output: Reference to a new complex whose value is the answer
inline CoolComplex CoolComplex::sinh () const {
return CoolComplex (::sinh (this->r), ::sinh (this->i));
}
// cosh -- Calculate the hyperbolic cosine of a CoolComplex number
// Input: Reference to a complex
// Output: Reference to a new complex whose value is the answer
inline CoolComplex CoolComplex::cosh () const {
return CoolComplex (::cosh (this->r), ::cosh (this->i));
}
// tanh -- Calculate the hyperbolic tangent of a CoolComplex number
// Input: Reference to a complex
// Output: Reference to a new complex whose value is the answer
inline CoolComplex CoolComplex::tanh () const {
return CoolComplex (::tanh (this->r), ::tanh (this->i));
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?