Complex Number 0.1.2 |
00001 // Copyright (c) 2010 Matthew Krupcale 00002 00003 // Permission is hereby granted, free of charge, to any person 00004 // obtaining a copy of this software and associated documentation 00005 // files (the "Software"), to deal in the Software without 00006 // restriction, including without limitation the rights to use, 00007 // copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 // copies of the Software, and to permit persons to whom the 00009 // Software is furnished to do so, subject to the following 00010 // conditions: 00011 00012 // The above copyright notice and this permission notice shall be 00013 // included in all copies or substantial portions of the Software. 00014 00015 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00016 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00017 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00018 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00019 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00020 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00021 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00022 // OTHER DEALINGS IN THE SOFTWARE. 00023 00024 #ifndef COMPLEX_MATH_H 00025 #define COMPLEX_MATH_H 00026 00027 //============================================================================ 00028 // Name : ComplexMath.h 00029 // Author : Matthew Krupcale 00030 // Version : 0.1.2 00031 // Copyright : Copyright (C) 2010 Matthew Krupcale 00032 // Description : A set of mathematical functions for complex numbers 00033 //============================================================================ 00034 00060 #ifndef M_El 00061 #define M_El 2.7182818284590452353602874713526625L /* e */ 00062 #endif 00063 00072 #ifndef M_LOG2El 00073 #define M_LOG2El 1.4426950408889634073599246810018921L /* log_2 e */ 00074 #endif 00075 00084 #ifndef M_LOG10El 00085 #define M_LOG10El 0.4342944819032518276511289189166051L /* log_10 e */ 00086 #endif 00087 00096 #ifndef M_LN2l 00097 #define M_LN2l 0.6931471805599453094172321214581766L /* log_e 2 */ 00098 #endif 00099 00108 #ifndef M_LN10l 00109 #define M_LN10l 2.3025850929940456840179914546843642L /* log_e 10 */ 00110 #endif 00111 00125 #ifndef M_PIl 00126 #define M_PIl 3.1415926535897932384626433832795029L /* pi */ 00127 #endif 00128 00137 #ifndef M_PI_2l 00138 #define M_PI_2l 1.5707963267948966192313216916397514L /* pi/2 */ 00139 #endif 00140 00149 #ifndef M_PI_4l 00150 #define M_PI_4l 0.7853981633974483096156608458198757L /* pi/4 */ 00151 #endif 00152 00161 #ifndef M_1_PIl 00162 #define M_1_PIl 0.3183098861837906715377675267450287L /* 1/pi */ 00163 #endif 00164 00173 #ifndef M_2_PIl 00174 #define M_2_PIl 0.6366197723675813430755350534900574L /* 2/pi */ 00175 #endif 00176 00185 #ifndef M_2_SQRTPIl 00186 #define M_2_SQRTPIl 1.1283791670955125738961589031215452L /* 2/sqrt(pi) */ 00187 #endif 00188 00197 #ifndef M_SQRT2l 00198 #define M_SQRT2l 1.4142135623730950488016887242096981L /* sqrt(2) */ 00199 #endif 00200 00209 #ifndef M_SQRT1_2l 00210 #define M_SQRT1_2l 0.7071067811865475244008443621048490L /* 1/sqrt(2) */ 00211 #endif 00212 00213 #include "ComplexNumber.h" 00214 #include "Namespace.h" 00215 #include <vector> 00216 00224 BEGIN_NAMESPACE(math) 00225 00226 00233 BEGIN_NAMESPACE(complex) 00234 00235 /********************************************************************** 00236 * Properties of complex numbers 00237 **********************************************************************/ 00238 00255 template <class T> 00256 T abs(const ComplexNumber<T>& z); 00257 00274 template <class T> 00275 T abs2(const ComplexNumber<T>& z); 00276 00306 template <class T> 00307 T arg(const ComplexNumber<T>& z); 00308 00327 template <class T> 00328 T logabs(const ComplexNumber<T>& z); 00329 00330 /********************************************************************** 00331 * Elementary complex functions 00332 **********************************************************************/ 00333 00350 template <class T> 00351 ComplexNumber<T> conjugate(const ComplexNumber<T>& z); 00352 00374 template <class T> 00375 ComplexNumber<T> exp(const ComplexNumber<T>& z); 00376 00393 template <class T> 00394 ComplexNumber<T> inverse(const ComplexNumber<T>& z); 00395 00416 template <class T> 00417 ComplexNumber<T> log(const ComplexNumber<T>& z); 00418 00443 template <class T> 00444 ComplexNumber<T> log(const T& x); 00445 00490 template <class T> 00491 ComplexNumber<T> log10(const ComplexNumber<T>& z); 00492 00538 template <class T> 00539 ComplexNumber<T> log10(const T& x); 00540 00589 template <class T> 00590 ComplexNumber<T> logb(const ComplexNumber<T>& z, 00591 const ComplexNumber<T>& b); 00592 00642 template <class T> 00643 ComplexNumber<T> logb(const ComplexNumber<T>& z, 00644 const T& b); 00645 00695 template <class T> 00696 ComplexNumber<T> logb(const T& x, 00697 const ComplexNumber<T>& b); 00698 00748 template <class T> 00749 ComplexNumber<T> logb(const T& x, 00750 const T& b); 00751 00772 template <class T> 00773 ComplexNumber<T> pow(const ComplexNumber<T>& a, 00774 const ComplexNumber<T>& b); 00775 00795 template <class T> 00796 ComplexNumber<T> pow(const ComplexNumber<T>& a, 00797 const T& b); 00798 00817 template <class T> 00818 ComplexNumber<T> pow(const T& a, 00819 const ComplexNumber<T>& b); 00820 00865 template <class T> 00866 ComplexNumber<T> sqrt(const ComplexNumber<T>& z); 00867 00885 template <class T> 00886 ComplexNumber<T> sqrt(const T& x); 00887 00932 template <class T> 00933 ComplexNumber<T> cbrt(const ComplexNumber<T>& z); 00934 00981 template <class T> 00982 ComplexNumber<T> nthRoot(const ComplexNumber<T>& z, 00983 const int n); 00984 01034 template <class T> 01035 std::vector<ComplexNumber<T> > nthRoots(const ComplexNumber<T>& z, 01036 const int n); 01037 01087 template <class T> 01088 void nthRoots(const ComplexNumber<T>& z, 01089 std::vector<ComplexNumber<T> > roots, 01090 const int n); 01091 01092 /*********************************************************************** 01093 * Complex trigonometric functions 01094 ***********************************************************************/ 01095 01151 template <class T> 01152 ComplexNumber<T> sin(const ComplexNumber<T>& z); 01153 01209 template <class T> 01210 ComplexNumber<T> cos(const ComplexNumber<T>& z); 01211 01289 template <class T> 01290 ComplexNumber<T> tan(const ComplexNumber<T>& z); 01291 01306 template <class T> 01307 ComplexNumber<T> csc(const ComplexNumber<T>& z); 01308 01323 template <class T> 01324 ComplexNumber<T> sec(const ComplexNumber<T>& z); 01325 01340 template <class T> 01341 ComplexNumber<T> cot(const ComplexNumber<T>& z); 01342 01343 /********************************************************************** 01344 * Inverse Complex Trigonometric Functions 01345 **********************************************************************/ 01346 01393 template <class T> 01394 ComplexNumber<T> asin(const ComplexNumber<T>& z); 01395 01474 template <class T> 01475 ComplexNumber<T> asin(const T& x); 01476 01523 template <class T> 01524 ComplexNumber<T> acos(const ComplexNumber<T>& z); 01525 01600 template <class T> 01601 ComplexNumber<T> acos(const T& x); 01602 01648 template <class T> 01649 ComplexNumber<T> atan(const ComplexNumber<T>& z); 01650 01666 template <class T> 01667 ComplexNumber<T> atan(const T& x); 01668 01695 template <class T> 01696 ComplexNumber<T> acsc(const ComplexNumber<T>& z); 01697 01724 template <class T> 01725 ComplexNumber<T> acsc(const T& x); 01726 01753 template <class T> 01754 ComplexNumber<T> asec(const ComplexNumber<T>& z); 01755 01782 template <class T> 01783 ComplexNumber<T> asec(const T& x); 01784 01811 template <class T> 01812 ComplexNumber<T> acot(const ComplexNumber<T>& z); 01813 01829 template <class T> 01830 ComplexNumber<T> acot(const T& x); 01831 01832 /********************************************************************** 01833 * Complex Hyperbolic Functions 01834 **********************************************************************/ 01835 01908 template <class T> 01909 ComplexNumber<T> sinh(const ComplexNumber<T>& z); 01910 01983 template <class T> 01984 ComplexNumber<T> cosh(const ComplexNumber<T>& z); 01985 02059 template <class T> 02060 ComplexNumber<T> tanh(const ComplexNumber<T>& z); 02061 02078 template <class T> 02079 ComplexNumber<T> csch(const ComplexNumber<T>& z); 02080 02097 template <class T> 02098 ComplexNumber<T> sech(const ComplexNumber<T>& z); 02099 02116 template <class T> 02117 ComplexNumber<T> coth(const ComplexNumber<T>& z); 02118 02119 /********************************************************************** 02120 * Inverse Complex Hyperbolic Functions 02121 **********************************************************************/ 02122 02169 template <class T> 02170 ComplexNumber<T> asinh(const ComplexNumber<T>& z); 02171 02218 template <class T> 02219 ComplexNumber<T> asinh(const T& x); 02220 02268 template <class T> 02269 ComplexNumber<T> acosh(const ComplexNumber<T>& z); 02270 02317 template <class T> 02318 ComplexNumber<T> acosh(const T& x); 02319 02364 template <class T> 02365 ComplexNumber<T> atanh(const ComplexNumber<T>& z); 02366 02411 template <class T> 02412 ComplexNumber<T> atanh(const T& x); 02413 02443 template <class T> 02444 ComplexNumber<T> acsch(const ComplexNumber<T>& z); 02445 02474 template <class T> 02475 ComplexNumber<T> acsch(const T& x); 02476 02505 template <class T> 02506 ComplexNumber<T> asech(const ComplexNumber<T>& z); 02507 02536 template <class T> 02537 ComplexNumber<T> asech(const T& x); 02538 02568 template <class T> 02569 ComplexNumber<T> acoth(const ComplexNumber<T>& z); 02570 02599 template <class T> 02600 ComplexNumber<T> acoth(const T& x); 02601 02602 END_NAMESPACE(complex) 02603 END_NAMESPACE(math) 02604 02605 #endif /* COMPLEX_MATH_H */