Add C++20 std::math constants shim (#1788)

Based on http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0631r7.pdf
This commit is contained in:
Tyler Veness
2019-07-31 22:15:22 -07:00
committed by Peter Johnson
parent dd43109596
commit 37d316aa09
11 changed files with 119 additions and 50 deletions

View File

@@ -11,6 +11,8 @@
#include <memory>
#include <random>
#include <wpi/math>
#include "gtest/gtest.h"
// Filter constants
@@ -36,8 +38,7 @@ std::ostream& operator<<(std::ostream& os,
}
static double GetData(double t) {
constexpr double kPi = 3.14159265358979323846;
return 100.0 * std::sin(2.0 * kPi * t);
return 100.0 * std::sin(2.0 * wpi::math::pi * t);
}
class LinearFilterNoiseTest

View File

@@ -12,6 +12,8 @@
#include <memory>
#include <random>
#include <wpi/math>
#include "gtest/gtest.h"
// Filter constants
@@ -52,8 +54,8 @@ std::ostream& operator<<(std::ostream& os,
}
static double GetData(double t) {
constexpr double kPi = 3.14159265358979323846;
return 100.0 * std::sin(2.0 * kPi * t) + 20.0 * std::cos(50.0 * kPi * t);
return 100.0 * std::sin(2.0 * wpi::math::pi * t) +
20.0 * std::cos(50.0 * wpi::math::pi * t);
}
static double GetPulseData(double t) {

View File

@@ -7,17 +7,18 @@
#include <cmath>
#include <wpi/math>
#include "frc/geometry/Rotation2d.h"
#include "gtest/gtest.h"
using namespace frc;
static constexpr double kEpsilon = 1E-9;
static constexpr double kPi = 3.14159265358979323846;
TEST(Rotation2dTest, RadiansToDegrees) {
const Rotation2d one{kPi / 3};
const Rotation2d two{kPi / 4};
const Rotation2d one{wpi::math::pi / 3};
const Rotation2d two{wpi::math::pi / 4};
EXPECT_NEAR(one.Degrees(), 60.0, kEpsilon);
EXPECT_NEAR(two.Degrees(), 45.0, kEpsilon);
@@ -27,15 +28,15 @@ TEST(Rotation2dTest, DegreesToRadians) {
const auto one = Rotation2d::FromDegrees(45.0);
const auto two = Rotation2d::FromDegrees(30.0);
EXPECT_NEAR(one.Radians(), kPi / 4.0, kEpsilon);
EXPECT_NEAR(two.Radians(), kPi / 6.0, kEpsilon);
EXPECT_NEAR(one.Radians(), wpi::math::pi / 4.0, kEpsilon);
EXPECT_NEAR(two.Radians(), wpi::math::pi / 6.0, kEpsilon);
}
TEST(Rotation2dTest, RotateByFromZero) {
const Rotation2d zero;
auto sum = zero + Rotation2d::FromDegrees(90.0);
EXPECT_NEAR(sum.Radians(), kPi / 2.0, kEpsilon);
EXPECT_NEAR(sum.Radians(), wpi::math::pi / 2.0, kEpsilon);
EXPECT_NEAR(sum.Degrees(), 90.0, kEpsilon);
}