| #pragma once |
| |
| #ifndef TMATH_UTIL_H |
| #define TMATH_UTIL_H |
| |
| |
| #include "texception.h" |
| |
| #include <numeric> |
| #include <complex> |
| |
| #ifndef __sgi |
| #include <cmath> |
| #else |
| #include <math.h> |
| #endif |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TNZCORE_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| enum TMathError { INFINITE_SOLUTIONS = -1 }; |
| |
| |
| |
| class DVAPI TMathException final : public TException { |
| TString m_msg; |
| |
| public: |
| TMathException(std::string msg); |
| virtual ~TMathException() {} |
| |
| TString getMessage() const override { return m_msg; } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI void tLUDecomposition(double *A, int n, int *indx, double &d); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI void tbackSubstitution(double *A, int n, int *indx, double *b); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI void tsolveSistem(double *A, int n, double *res); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| inline void tsolveSistem(std::vector<double> &A, std::vector<double> &res) { |
| assert(res.size() * res.size() == A.size()); |
| tsolveSistem(&A[0], res.size(), &res[0]); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI double tdet(double *A, int n); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI double tdet(double *LUa, int n, double d); |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI int rootFinding(const std::vector<double> &poly, |
| std::vector<double> &sol); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int solveEquation2(std::complex<double> *roots, double a, double b, double c); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int solveEquation3(std::complex<double> *roots, double a, double b, double c, double d); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int solveEquation4(std::complex<double> *roots, double a, double b, double c, double d, double e); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| inline bool isAlmostZero(double val, double eps = TConsts::epsilon) { |
| return -eps < val && val < eps; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| inline bool isAlmostZero(std::complex<double> val, double eps = TConsts::epsilon) { |
| return val.real()*val.real() + val.imag()*val.imag() < eps*eps; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI int numberOfRootsInInterval(int order, const double *polyH, double min, |
| double max); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI double cubicRoot(double a, double b, double c, double d); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| DVAPI double quadraticRoot(double a, double b, double c); |
| |
| |
| |
| #endif |
| |
| |
| |