ExpEstimate.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.12.23
  7. #pragma once
  8. #include <Mathematics/Exp2Estimate.h>
  9. // Minimax polynomial approximations to 2^x. The polynomial p(x) of
  10. // degree D minimizes the quantity maximum{|2^x - p(x)| : x in [0,1]}
  11. // over all polynomials of degree D. The natural exponential is
  12. // computed using exp(x) = 2^{x/log(2)}, where log(2) is the natural
  13. // logarithm of 2.
  14. namespace WwiseGTE
  15. {
  16. template <typename Real>
  17. class ExpEstimate
  18. {
  19. public:
  20. // The input constraint is x in [0,1]. For example,
  21. // float x; // in [0,1]
  22. // float result = ExpEstimate<float>::Degree<3>(x);
  23. template <int D>
  24. inline static Real Degree(Real x)
  25. {
  26. return Exp2Estimate<Real>::Degree<D>(x * (Real)GTE_C_INV_LN_2);
  27. }
  28. // The input x can be any real number. Range reduction is used to
  29. // generate a value y in [0,1], call Degree(y), and combine the output
  30. // with the proper exponent to obtain the approximation. For example,
  31. // float x; // x >= 0
  32. // float result = ExpEstimate<float>::DegreeRR<3>(x);
  33. template <int D>
  34. inline static Real DegreeRR(Real x)
  35. {
  36. return Exp2Estimate<Real>::DegreeRR<D>(x * (Real)GTE_C_INV_LN_2);
  37. }
  38. };
  39. }