From a6f3e5ff1e89c16b8afdee20a5573780d428d08e Mon Sep 17 00:00:00 2001 From: Shobuj Paul Date: Sat, 17 Feb 2024 22:59:56 +0530 Subject: [PATCH] Updated with pre-commit --- include/math/cordic.hpp | 14 +++++++------- src/math/cordic.cpp | 8 ++++---- tests/cordic_algo_test.cpp | 17 ++++++++++------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/math/cordic.hpp b/include/math/cordic.hpp index 6e7db91..683dbca 100644 --- a/include/math/cordic.hpp +++ b/include/math/cordic.hpp @@ -4,10 +4,10 @@ namespace CORDIC { - struct Trig - { - int sin; - int cos; - }; - Trig trig(int angle); -} +struct Trig +{ + int sin; + int cos; +}; +Trig trig(int angle); +} // namespace CORDIC diff --git a/src/math/cordic.cpp b/src/math/cordic.cpp index cb63883..9226ef5 100644 --- a/src/math/cordic.cpp +++ b/src/math/cordic.cpp @@ -1,10 +1,10 @@ -#include +#include CORDIC::Trig CORDIC::trig(int angle) { - int32_t atan2[14] = {8192, 4836, 2555, 1297, 651, 325, 162, 81, 40, 20, 10, 5, 2, 1}; + int32_t atan2[14] = { 8192, 4836, 2555, 1297, 651, 325, 162, 81, 40, 20, 10, 5, 2, 1 }; int32_t x = 9949, y = 0, theta = 0; - for(int32_t i = 0; i < 14; i++) + for (int32_t i = 0; i < 14; i++) { int32_t sigma = (theta < angle) ? 1 : -1; theta = theta + sigma * atan2[i]; @@ -12,5 +12,5 @@ CORDIC::Trig CORDIC::trig(int angle) y = y + sigma * (x >> i); x = nx; } - return {y, x}; + return { y, x }; } diff --git a/tests/cordic_algo_test.cpp b/tests/cordic_algo_test.cpp index 58751f6..b3745ab 100644 --- a/tests/cordic_algo_test.cpp +++ b/tests/cordic_algo_test.cpp @@ -3,9 +3,9 @@ #include #include -int main(int argc, char **argv) +int main(int argc, char** argv) { - if(argc != 2) + if (argc != 2) { std::cerr << "Usage: " << argv[0] << " " << std::endl; return 1; @@ -13,10 +13,13 @@ int main(int argc, char **argv) int angle = atoi(argv[1]); int angle_cordic = (angle << 16) / 360; CORDIC::Trig trig = CORDIC::trig(angle_cordic); - std::cout << "sin(x) in cru = " << trig.sin << " " << "cos(x) in cru = " << trig.cos << std::endl; - float sine = (float)trig.sin/16384.0F; - float cosine = (float)trig.cos/16384.0F; - std::cout << "std::sin(x) error = " << std::sin(angle*PI/180) - sine << " " << "std::cos(x) error = " << std::cos(angle*PI/180) - cosine << std::endl; - std::cout << "math::sin(x) error = " << math::sin(angle*PI/180) - sine << " " << "math::cos(x) error = " << math::cos(angle*PI/180) - cosine << std::endl; + std::cout << "sin(x) in cru = " << trig.sin << " " + << "cos(x) in cru = " << trig.cos << std::endl; + float sine = (float)trig.sin / 16384.0F; + float cosine = (float)trig.cos / 16384.0F; + std::cout << "std::sin(x) error = " << std::sin(angle * PI / 180) - sine << " " + << "std::cos(x) error = " << std::cos(angle * PI / 180) - cosine << std::endl; + std::cout << "math::sin(x) error = " << math::sin(angle * PI / 180) - sine << " " + << "math::cos(x) error = " << math::cos(angle * PI / 180) - cosine << std::endl; return 0; }