LogEstimate.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/Log2Estimate.h>
  9. // Minimax polynomial approximations to log2(x). The polynomial p(x) of
  10. // degree D minimizes the quantity maximum{|log2(x) - p(x)| : x in [1,2]}
  11. // over all polynomials of degree D. The natural logarithm is computed
  12. // using log(x) = log2(x)/log2(e) = log2(x)*log(2).
  13. namespace WwiseGTE
  14. {
  15. template <typename Real>
  16. class LogEstimate
  17. {
  18. public:
  19. // The input constraint is x in [1,2]. For example,
  20. // float x; // in [1,2]
  21. // float result = LogEstimate<float>::Degree<3>(x);
  22. template <int D>
  23. inline static Real Degree(Real x)
  24. {
  25. return Log2Estimate<Real>::Degree<D>(x) * (Real)GTE_C_LN_2;
  26. }
  27. // The input constraint is x > 0. Range reduction is used to generate
  28. // a value y in (0,1], call Degree(y), and add the exponent for the
  29. // power of two in the binary scientific representation of x. For
  30. // example,
  31. // float x; // x > 0
  32. // float result = LogEstimate<float>::DegreeRR<3>(x);
  33. template <int D>
  34. inline static Real DegreeRR(Real x)
  35. {
  36. return Log2Estimate<Real>::DegreeRR<D>(x) * (Real)GTE_C_LN_2;
  37. }
  38. };
  39. }