-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be6f01f
commit 6741597
Showing
5 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <etl/cmath.hpp> | ||
#include <etl/numbers.hpp> | ||
|
||
namespace grit { | ||
|
||
/// \ingroup grit-math | ||
template<etl::floating_point Float> | ||
[[nodiscard]] constexpr auto bhaskara(Float x) -> Float | ||
{ | ||
auto const pi = static_cast<Float>(etl::numbers::pi); | ||
auto const num = Float(16) * x * (pi - x); | ||
auto const denom = Float(5) * pi * pi - Float(4) * x * (pi - x); | ||
return num / denom; | ||
} | ||
|
||
} // namespace grit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "trigonometry.hpp" | ||
|
||
#include <catch2/catch_template_test_macros.hpp> | ||
#include <catch2/matchers/catch_matchers_floating_point.hpp> | ||
|
||
TEMPLATE_TEST_CASE("math: bhaskara", "", float, double) | ||
{ | ||
using Float = TestType; | ||
|
||
REQUIRE_THAT(grit::bhaskara(Float(0.0)), Catch::Matchers::WithinAbs(0.0, 1e-8)); | ||
REQUIRE_THAT(grit::bhaskara(Float(0.5)), Catch::Matchers::WithinAbs(0.479426, 1e-2)); | ||
REQUIRE_THAT(grit::bhaskara(Float(1.0)), Catch::Matchers::WithinAbs(0.841471, 1e-2)); | ||
REQUIRE_THAT(grit::bhaskara(Float(etl::numbers::pi / 3.0)), Catch::Matchers::WithinAbs(0.866025, 1e-2)); | ||
REQUIRE_THAT(grit::bhaskara(Float(etl::numbers::pi / 2.0)), Catch::Matchers::WithinAbs(1.0, 1e-8)); | ||
} |