Use our own constants instead of M_PI, M_*, etc. (#1733)
These constants are not part of the standard. We instead use our own constexpr definitions in the filament::math namespace, as part of the scalar.h include.
This commit is contained in:
@@ -18,9 +18,11 @@
|
||||
#define TNT_MATH_FAST_H
|
||||
|
||||
#include <cmath>
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
#include <math/compiler.h>
|
||||
#include <math/scalar.h>
|
||||
|
||||
#ifdef __ARM_NEON
|
||||
#include <arm_neon.h>
|
||||
@@ -35,7 +37,7 @@ namespace fast {
|
||||
// x between -pi and pi
|
||||
template<typename T, typename = std::enable_if_t<std::is_floating_point<T>::value>>
|
||||
constexpr T MATH_PURE cos(T x) noexcept {
|
||||
x *= T(M_1_PI / 2);
|
||||
x *= T(F_1_PI / 2);
|
||||
x -= T(0.25) + std::floor(x + T(0.25));
|
||||
x *= T(16.0) * std::abs(x) - T(8.0);
|
||||
x += T(0.225) * x * (std::abs(x) - T(1.0));
|
||||
@@ -47,7 +49,7 @@ constexpr T MATH_PURE cos(T x) noexcept {
|
||||
// x between -pi and pi
|
||||
template<typename T, typename = std::enable_if_t<std::is_floating_point<T>::value>>
|
||||
constexpr T MATH_PURE sin(T x) noexcept {
|
||||
return filament::math::fast::cos<T>(x - T(M_PI_2));
|
||||
return filament::math::fast::cos<T>(x - T(F_PI_2));
|
||||
}
|
||||
|
||||
constexpr inline float MATH_PURE ilog2(float x) noexcept {
|
||||
|
||||
@@ -24,6 +24,20 @@
|
||||
namespace filament {
|
||||
namespace math {
|
||||
|
||||
constexpr const double F_E = 2.71828182845904523536028747135266250;
|
||||
constexpr const double F_LOG2E = 1.44269504088896340735992468100189214;
|
||||
constexpr const double F_LOG10E = 0.434294481903251827651128918916605082;
|
||||
constexpr const double F_LN2 = 0.693147180559945309417232121458176568;
|
||||
constexpr const double F_LN10 = 2.30258509299404568401799145468436421;
|
||||
constexpr const double F_PI = 3.14159265358979323846264338327950288;
|
||||
constexpr const double F_PI_2 = 1.57079632679489661923132169163975144;
|
||||
constexpr const double F_PI_4 = 0.785398163397448309615660845819875721;
|
||||
constexpr const double F_1_PI = 0.318309886183790671537767526745028724;
|
||||
constexpr const double F_2_PI = 0.636619772367581343075535053490057448;
|
||||
constexpr const double F_2_SQRTPI = 1.12837916709551257389615890312154517;
|
||||
constexpr const double F_SQRT2 = 1.41421356237309504880168872420969808;
|
||||
constexpr const double F_SQRT1_2 = 0.707106781186547524400844362104849039;
|
||||
|
||||
template<typename T>
|
||||
inline constexpr T MATH_PURE saturate(T v) noexcept {
|
||||
return T(std::min(T(1), std::max(T(0), v)));
|
||||
|
||||
Reference in New Issue
Block a user