From 0c6e215cbd24aff28db1d453f08fde5c22129105 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Tue, 21 Nov 2017 16:35:16 +0000 Subject: [PATCH 1/2] Add workaround for gcc bug 58541 The bug in question causes a "redeclaration differs in constexpr" error, despite the standard not requiring this. This bug is fixed in newer versions of gcc. More information can be found [here](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58541). --- src/FixedPoints/SFixed.h | 41 ++++++++-------------------------------- src/FixedPoints/UFixed.h | 41 ++++++++-------------------------------- 2 files changed, 16 insertions(+), 66 deletions(-) diff --git a/src/FixedPoints/SFixed.h b/src/FixedPoints/SFixed.h index fcf1f7b..04ad53b 100644 --- a/src/FixedPoints/SFixed.h +++ b/src/FixedPoints/SFixed.h @@ -89,42 +89,17 @@ public: SFixed & operator /=(const SFixed & other); public: - const static SFixed Epsilon; - const static SFixed MinValue; - const static SFixed MaxValue; + constexpr const static SFixed Epsilon = SFixed::fromInternal(1); + constexpr const static SFixed MinValue = SFixed::fromInternal(FIXED_POINTS_DETAILS::MsbMask::Value); + constexpr const static SFixed MaxValue = SFixed::fromInternal(~FIXED_POINTS_DETAILS::MsbMask::Value); - const static SFixed Pi; - const static SFixed E; - const static SFixed Phi; - const static SFixed Tau; + // 40 digits is probably enough for these + constexpr const static SFixed Pi = 3.1415926535897932384626433832795028841971; + constexpr const static SFixed E = 2.718281828459045235360287471352662497757; + constexpr const static SFixed Phi = 1.6180339887498948482045868343656381177203; + constexpr const static SFixed Tau = 6.2831853071795864769252867665590057683943; }; -// -// Variables -// - -template< unsigned Integer, unsigned Fraction > -constexpr const SFixed SFixed::Epsilon = SFixed::fromInternal(1); - -template< unsigned Integer, unsigned Fraction > -constexpr const SFixed SFixed::MinValue = SFixed::fromInternal(FIXED_POINTS_DETAILS::MsbMask::Value); - -template< unsigned Integer, unsigned Fraction > -constexpr const SFixed SFixed::MaxValue = SFixed::fromInternal(~FIXED_POINTS_DETAILS::MsbMask::Value); - -// 40 digits is probably enough for these -template< unsigned Integer, unsigned Fraction > -constexpr const SFixed SFixed::Pi = 3.1415926535897932384626433832795028841971; - -template< unsigned Integer, unsigned Fraction > -constexpr const SFixed SFixed::E = 2.718281828459045235360287471352662497757; - -template< unsigned Integer, unsigned Fraction > -constexpr const SFixed SFixed::Phi = 1.6180339887498948482045868343656381177203; - -template< unsigned Integer, unsigned Fraction > -constexpr const SFixed SFixed::Tau = 6.2831853071795864769252867665590057683943; - // // Free functions diff --git a/src/FixedPoints/UFixed.h b/src/FixedPoints/UFixed.h index 3615961..3becdf5 100644 --- a/src/FixedPoints/UFixed.h +++ b/src/FixedPoints/UFixed.h @@ -88,42 +88,17 @@ public: UFixed & operator /=(const UFixed & other); public: - const static UFixed Epsilon; - const static UFixed MinValue; - const static UFixed MaxValue; + constexpr const static UFixed Epsilon = UFixed::fromInternal(1); + constexpr const static UFixed MinValue = UFixed::fromInternal(0); + constexpr const static UFixed MaxValue = UFixed::fromInternal(~0); - const static UFixed Pi; - const static UFixed E; - const static UFixed Phi; - const static UFixed Tau; + // 40 digits is probably enough for these + constexpr const static UFixed Pi = 3.1415926535897932384626433832795028841971; + constexpr const static UFixed E = 2.718281828459045235360287471352662497757; + constexpr const static UFixed Phi = 1.6180339887498948482045868343656381177203; + constexpr const static UFixed Tau = 6.2831853071795864769252867665590057683943; }; -// -// Variables -// - -template< unsigned Integer, unsigned Fraction > -constexpr const UFixed UFixed::Epsilon = UFixed::fromInternal(1); - -template< unsigned Integer, unsigned Fraction > -constexpr const UFixed UFixed::MinValue = UFixed::fromInternal(0); - -template< unsigned Integer, unsigned Fraction > -constexpr const UFixed UFixed::MaxValue = UFixed::fromInternal(~0); - -// 40 digits is probably enough for these -template< unsigned Integer, unsigned Fraction > -constexpr const UFixed UFixed::Pi = 3.1415926535897932384626433832795028841971; - -template< unsigned Integer, unsigned Fraction > -constexpr const UFixed UFixed::E = 2.718281828459045235360287471352662497757; - -template< unsigned Integer, unsigned Fraction > -constexpr const UFixed UFixed::Phi = 1.6180339887498948482045868343656381177203; - -template< unsigned Integer, unsigned Fraction > -constexpr const UFixed UFixed::Tau = 6.2831853071795864769252867665590057683943; - // // Free functions From 6794d431cf3842642f81e1c1812afd9f58fb82e6 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Tue, 21 Nov 2017 16:39:09 +0000 Subject: [PATCH 2/2] Add support for ESP8266 Automatically disables random number functionality for ESP8266. --- src/FixedPoints/Details.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/FixedPoints/Details.h b/src/FixedPoints/Details.h index 5c183b4..105d3eb 100644 --- a/src/FixedPoints/Details.h +++ b/src/FixedPoints/Details.h @@ -31,6 +31,10 @@ #define FIXED_POINTS_DETAILS FixedPointsDetails #endif +#if defined(ESP8266) +#define FIXED_POINTS_NO_RANDOM +#endif + // Pay no attention to the man behind the curtains FIXED_POINTS_BEGIN_NAMESPACE