123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #pragma once
- #include <Mathematics/Math.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class TanEstimate
- {
- public:
-
-
-
- template <int D>
- inline static Real Degree(Real x)
- {
- return Evaluate(degree<D>(), x);
- }
-
-
-
-
-
-
-
-
-
- template <int D>
- inline static Real DegreeRR(Real x)
- {
- Real y;
- Reduce(x, y);
- if (std::fabs(y) <= (Real)GTE_C_QUARTER_PI)
- {
- return Degree<D>(y);
- }
- else if (y > (Real)GTE_C_QUARTER_PI)
- {
- Real poly = Degree<D>(y - (Real)GTE_C_QUARTER_PI);
- return ((Real)1 + poly) / ((Real)1 - poly);
- }
- else
- {
- Real poly = Degree<D>(y + (Real)GTE_C_QUARTER_PI);
- return -((Real)1 - poly) / ((Real)1 + poly);
- }
- }
- private:
-
-
- template <int D> struct degree {};
- inline static Real Evaluate(degree<3>, Real x)
- {
- Real xsqr = x * x;
- Real poly;
- poly = (Real)GTE_C_TAN_DEG3_C1;
- poly = (Real)GTE_C_TAN_DEG3_C0 + poly * xsqr;
- poly = poly * x;
- return poly;
- }
- inline static Real Evaluate(degree<5>, Real x)
- {
- Real xsqr = x * x;
- Real poly;
- poly = (Real)GTE_C_TAN_DEG5_C2;
- poly = (Real)GTE_C_TAN_DEG5_C1 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG5_C0 + poly * xsqr;
- poly = poly * x;
- return poly;
- }
- inline static Real Evaluate(degree<7>, Real x)
- {
- Real xsqr = x * x;
- Real poly;
- poly = (Real)GTE_C_TAN_DEG7_C3;
- poly = (Real)GTE_C_TAN_DEG7_C2 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG7_C1 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG7_C0 + poly * xsqr;
- poly = poly * x;
- return poly;
- }
- inline static Real Evaluate(degree<9>, Real x)
- {
- Real xsqr = x * x;
- Real poly;
- poly = (Real)GTE_C_TAN_DEG9_C4;
- poly = (Real)GTE_C_TAN_DEG9_C3 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG9_C2 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG9_C1 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG9_C0 + poly * xsqr;
- poly = poly * x;
- return poly;
- }
- inline static Real Evaluate(degree<11>, Real x)
- {
- Real xsqr = x * x;
- Real poly;
- poly = (Real)GTE_C_TAN_DEG11_C5;
- poly = (Real)GTE_C_TAN_DEG11_C4 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG11_C3 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG11_C2 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG11_C1 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG11_C0 + poly * xsqr;
- poly = poly * x;
- return poly;
- }
- inline static Real Evaluate(degree<13>, Real x)
- {
- Real xsqr = x * x;
- Real poly;
- poly = (Real)GTE_C_TAN_DEG13_C6;
- poly = (Real)GTE_C_TAN_DEG13_C5 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG13_C4 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG13_C3 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG13_C2 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG13_C1 + poly * xsqr;
- poly = (Real)GTE_C_TAN_DEG13_C0 + poly * xsqr;
- poly = poly * x;
- return poly;
- }
-
- inline static void Reduce(Real x, Real& y)
- {
-
- y = std::fmod(x, (Real)GTE_C_PI);
-
- if (y > (Real)GTE_C_HALF_PI)
- {
- y -= (Real)GTE_C_PI;
- }
- else if (y < (Real)-GTE_C_HALF_PI)
- {
- y += (Real)GTE_C_PI;
- }
- }
- };
- }
|