-
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.
Adding sin and cosine approximations
- Loading branch information
1 parent
fa44c50
commit d06887a
Showing
7 changed files
with
114 additions
and
15 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
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 |
---|---|---|
@@ -1,3 +1,46 @@ | ||
// | ||
// Created by jatin on 11/22/23. | ||
// | ||
#include "test_helpers.hpp" | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <iostream> | ||
|
||
#include <math_approx/math_approx.hpp> | ||
|
||
TEST_CASE ("Cosine Approx Test") | ||
{ | ||
#if ! defined(WIN32) | ||
const auto all_floats = test_helpers::all_32_bit_floats (-10.0f, 10.0f, 1.0e-3f); | ||
#else | ||
const auto all_floats = test_helpers::all_32_bit_floats (-10.0f, 10.0f, 1.0e-1f); | ||
#endif | ||
const auto y_exact = test_helpers::compute_all (all_floats, [] (auto x) | ||
{ return std::cos (x); }); | ||
|
||
const auto test_approx = [&all_floats, &y_exact] (auto&& f_approx, float err_bound) | ||
{ | ||
const auto y_approx = test_helpers::compute_all (all_floats, f_approx); | ||
|
||
const auto error = test_helpers::compute_error (y_exact, y_approx); | ||
const auto max_error = test_helpers::abs_max (error); | ||
|
||
std::cout << max_error << std::endl; | ||
REQUIRE (std::abs (max_error) < err_bound); | ||
}; | ||
|
||
SECTION ("9th-Order") | ||
{ | ||
test_approx ([] (auto x) | ||
{ return math_approx::cos<9> (x); }, | ||
7.0e-7f); | ||
} | ||
SECTION ("7th-Order") | ||
{ | ||
test_approx ([] (auto x) | ||
{ return math_approx::cos<7> (x); }, | ||
1.8e-5f); | ||
} | ||
SECTION ("5th-Order") | ||
{ | ||
test_approx ([] (auto x) | ||
{ return math_approx::cos<5> (x); }, | ||
7.5e-4f); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,46 @@ | ||
// | ||
// Created by jatin on 11/22/23. | ||
// | ||
#include "test_helpers.hpp" | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <iostream> | ||
|
||
#include <math_approx/math_approx.hpp> | ||
|
||
TEST_CASE ("Sine Approx Test") | ||
{ | ||
#if ! defined(WIN32) | ||
const auto all_floats = test_helpers::all_32_bit_floats (-10.0f, 10.0f, 1.0e-3f); | ||
#else | ||
const auto all_floats = test_helpers::all_32_bit_floats (-10.0f, 10.0f, 1.0e-1f); | ||
#endif | ||
const auto y_exact = test_helpers::compute_all (all_floats, [] (auto x) | ||
{ return std::sin (x); }); | ||
|
||
const auto test_approx = [&all_floats, &y_exact] (auto&& f_approx, float err_bound) | ||
{ | ||
const auto y_approx = test_helpers::compute_all (all_floats, f_approx); | ||
|
||
const auto error = test_helpers::compute_error (y_exact, y_approx); | ||
const auto max_error = test_helpers::abs_max (error); | ||
|
||
// std::cout << max_error << std::endl; | ||
REQUIRE (std::abs (max_error) < err_bound); | ||
}; | ||
|
||
SECTION ("9th-Order") | ||
{ | ||
test_approx ([] (auto x) | ||
{ return math_approx::sin<9> (x); }, | ||
8.5e-7f); | ||
} | ||
SECTION ("7th-Order") | ||
{ | ||
test_approx ([] (auto x) | ||
{ return math_approx::sin<7> (x); }, | ||
1.8e-5f); | ||
} | ||
SECTION ("5th-Order") | ||
{ | ||
test_approx ([] (auto x) | ||
{ return math_approx::sin<5> (x); }, | ||
7.5e-4f); | ||
} | ||
} |
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