Skip to content

Commit

Permalink
Added build types and changed sin implementation for compiler optimiz…
Browse files Browse the repository at this point in the history
…ation friendly
  • Loading branch information
Shobuj-Paul committed Feb 18, 2024
1 parent a6f3e5f commit f585293
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O3")

include(CTest)
enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fi
cd ${BUILD_DIR}

# Configure and build the project.
cmake ..
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4

# If make completes successfully, run ctest
Expand Down
6 changes: 3 additions & 3 deletions src/math/cordic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
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 x = 9949, y = 0, theta = 0;
int32_t x = 9949, y = 0, theta = 0, sigma, nx;
for (int32_t i = 0; i < 14; i++)
{
int32_t sigma = (theta < angle) ? 1 : -1;
sigma = (theta < angle) ? 1 : -1;
theta = theta + sigma * atan2[i];
int32_t nx = x - sigma * (y >> i);
nx = x - sigma * (y >> i);
y = y + sigma * (x >> i);
x = nx;
}
Expand Down
6 changes: 5 additions & 1 deletion src/math/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ float math::sin(float angle)
angle = PI - angle;
else if (angle < -PI / 2)
angle = -PI - angle;
return (angle - pow(angle, 3) / 6 + pow(angle, 5) / 120 - pow(angle, 7) / 5040);
float pow_2 = angle * angle;
float pow_3 = pow_2 * angle;
float pow_5 = pow_3 * pow_2;
float pow_7 = pow_5 * pow_2;
return (angle - pow_3 * 0.1667 + pow_5 * 0.008333 - pow_7 * 0.0001984);
}

float math::cos(float angle)
Expand Down

0 comments on commit f585293

Please sign in to comment.