Skip to content

Commit

Permalink
Attempt to fix C++20 'compliant' compilers that don't actually suppor…
Browse files Browse the repository at this point in the history
…t <numbers>.
  • Loading branch information
sa666666 committed May 13, 2024
1 parent cd1095b commit 49166ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/common/HighScoresManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
*/

#include <cmath>
#include <numbers>

#include "OSystem.hxx"
#include "PropsSet.hxx"
Expand Down Expand Up @@ -463,8 +462,8 @@ Int32 HighScoresManager::convert(Int32 val, uInt32 maxVal, bool isBCD,
//maxVal += zeroBased ? 0 : 1;
maxVal -= zeroBased ? 1 : 0;
const Int32 bits = isBCD
? ceil(log(maxVal) / std::numbers::ln10 * 4)
: ceil(log(maxVal) / std::numbers::ln2);
? ceil(log(maxVal) / BSPF::ln10 * 4)
: ceil(log(maxVal) / BSPF::ln2);

// limit to maxVal's bits
val %= 1 << bits;
Expand Down
19 changes: 18 additions & 1 deletion src/common/bspf.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ using uInt64 = uint64_t;
#include <functional>
#include <iomanip>
#include <memory>
#include <numbers>
#include <string>
#include <string_view>
#include <charconv>
Expand All @@ -59,6 +58,11 @@ using uInt64 = uint64_t;
#include <utility>
#include <vector>

// It seems not all C++20 implementations support this yet
#if __has_include(<numbers>)
#include <numbers>
#endif

using std::cin;
using std::cout;
using std::cerr;
Expand Down Expand Up @@ -117,8 +121,21 @@ static const string EmptyString("");

namespace BSPF
{
#if __has_include(<numbers>)
static constexpr float PI_f = std::numbers::pi_v<float>;
static constexpr double PI_d = std::numbers::pi_v<double>;
static constexpr double ln10 = std::numbers::ln10;
static constexpr double ln2 = std::numbers::ln2;
#else
[[deprecated("C++20 implementation missing <numbers> support.")]]
static constexpr float PI_f = 3.141592653589793238462643383279502884F;
[[deprecated("C++20 implementation missing <numbers> support.")]]
static constexpr double PI_d = 3.141592653589793238462643383279502884;
[[deprecated("C++20 implementation missing <numbers> support.")]]
static constexpr double ln10 = 2.302585092994045684017991454684364208;
[[deprecated("C++20 implementation missing <numbers> support.")]]
static constexpr double ln2 = 0.693147180559945309417232121458176568;
#endif

// CPU architecture type
// This isn't complete yet, but takes care of all the major platforms
Expand Down

0 comments on commit 49166ca

Please sign in to comment.