From 7d30c30819e9f2f908569b9948077a3a8823de69 Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Mon, 27 Nov 2017 17:36:33 +0000 Subject: [PATCH] Fixed some GCC constexpr issues --- modules/juce_core/maths/juce_MathsFunctions.h | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/modules/juce_core/maths/juce_MathsFunctions.h b/modules/juce_core/maths/juce_MathsFunctions.h index 5f4f827bd1..77b8c41231 100644 --- a/modules/juce_core/maths/juce_MathsFunctions.h +++ b/modules/juce_core/maths/juce_MathsFunctions.h @@ -279,7 +279,7 @@ void ignoreUnused (Types&&...) noexcept {} @endcode */ template -JUCE_CONSTEXPR int numElementsInArray (Type (&array)[N]) +int numElementsInArray (Type (&array)[N]) { (void) array; (void) sizeof (0[array]); // This line should cause an error if you pass an object with a user-defined subscript operator @@ -327,6 +327,21 @@ inline int64 abs64 (const int64 n) noexcept //============================================================================== +#if JUCE_HAS_CONSTEXPR + +/** Commonly used mathematical constants */ +template +struct MathConstants +{ + /** A predefined value for Pi */ + static constexpr FloatType pi = static_cast (3.141592653589793238L); + + /** A predfined value for Euler's number */ + static constexpr FloatType euler = static_cast (2.71828182845904523536L); +}; + +#else + /** Commonly used mathematical constants */ template struct MathConstants @@ -344,16 +359,18 @@ const FloatType MathConstants::pi = static_cast (3.1415926 template const FloatType MathConstants::euler = static_cast (2.71828182845904523536L); +#endif + /** A predefined value for Pi, at double-precision. @see float_Pi */ -const double double_Pi = MathConstants::pi; +const JUCE_CONSTEXPR double double_Pi = MathConstants::pi; /** A predefined value for Pi, at single-precision. @see double_Pi */ -const float float_Pi = MathConstants::pi; +const JUCE_CONSTEXPR float float_Pi = MathConstants::pi; /** Converts an angle in degrees to radians. */ @@ -516,7 +533,7 @@ JUCE_CONSTEXPR bool isPowerOfTwo (IntegerType value) } /** Returns the smallest power-of-two which is equal to or greater than the given integer. */ -inline JUCE_CONSTEXPR int nextPowerOfTwo (int n) noexcept +inline int nextPowerOfTwo (int n) noexcept { --n; n |= (n >> 1); @@ -534,7 +551,7 @@ inline JUCE_CONSTEXPR int nextPowerOfTwo (int n) noexcept int findHighestSetBit (uint32 n) noexcept; /** Returns the number of bits in a 32-bit integer. */ -inline JUCE_CONSTEXPR int countNumberOfBits (uint32 n) noexcept +inline int countNumberOfBits (uint32 n) noexcept { n -= ((n >> 1) & 0x55555555); n = (((n >> 2) & 0x33333333) + (n & 0x33333333)); @@ -545,7 +562,7 @@ inline JUCE_CONSTEXPR int countNumberOfBits (uint32 n) noexcept } /** Returns the number of bits in a 64-bit integer. */ -inline JUCE_CONSTEXPR int countNumberOfBits (uint64 n) noexcept +inline int countNumberOfBits (uint64 n) noexcept { return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32)); }