Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Bać committed Jul 23, 2024
1 parent edc23c5 commit 0e81bf6
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 409 deletions.
7 changes: 7 additions & 0 deletions fixed_lib/include/fixedmath/fixed_math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ namespace func
return fobj::floor(value);
}

template<std::integral integral_type>
[[nodiscard, gnu::const, gnu::always_inline]]
constexpr auto angle_to_radians(integral_type angle) noexcept -> fixed_t
{
return fobj::angle_to_radians(angle);
}

[[nodiscard]]
constexpr auto sqrt(std::same_as<fixed_t> auto value) noexcept -> fixed_t
{
Expand Down
3 changes: 2 additions & 1 deletion fixed_lib/include/fixedmath/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,12 @@ struct angle_to_radians_t
{
///\brief converts angle 0 - 360 to radians.
template<std::integral integral_type>
requires(sizeof(integral_type) > 1)
[[nodiscard, gnu::const, gnu::always_inline]]
static constexpr auto operator()(integral_type angle) noexcept -> fixed_t
{
if(angle >= integral_type(0) && angle <= integral_type(360))
return integral_to_fixed(angle) * fixedmath::phi / 180;
return division(multiply(arithmetic_to_fixed(angle), fixedmath::phi), 180);
return quiet_NaN_result();
}
};
Expand Down
12 changes: 3 additions & 9 deletions unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,9 @@ add_fixedmath_ut( addition_ut )
add_fixedmath_ut( subtraction_ut )
add_fixedmath_ut( sqrt_ut )
add_fixedmath_ut( multiplication_ut )
# add_compile_test( division )
#
# add_compile_test( misc_functions )
# add_compile_test( sin )
add_fixedmath_ut( division_ut )
add_fixedmath_ut( misc_functions_ut )
add_fixedmath_ut( sin_cos_ut )
# add_compile_test( tan )
# add_compile_test( atan )

# add_executable( hypot_not_abacus hypot_not_abacus.cc )
# target_link_libraries( hypot_not_abacus fixed_math )

# add_executable( tests tests.cc )
# target_link_libraries( tests fixed_math stralgo::stralgo )
83 changes: 83 additions & 0 deletions unit_tests/division_ut.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <unit_test_core.h>
#include <unit_test_common.h>

using boost::ut::operator""_test;
using namespace metatests;
using namespace fixedmath;
using namespace fixedmath::func;

int main()
{
test_result result;

"division"_test = [&result]
{
auto fn_tmpl = [] -> metatests::test_result
{
expect_eq(1_fix / 1_fix, 1_fix);
expect_eq(-1_fix / 1_fix, -1_fix);
expect_eq(1_fix / -1_fix, -1_fix);
expect_eq(-1_fix / -1_fix, 1_fix);
expect_eq(1_fix / 1, 1_fix);
expect_eq(100_fix / 10_fix, 10_fix);
expect_eq(100_fix / 10, 10_fix);
expect_eq(-10_fix / 1, -10_fix);
expect_eq(-10_fix / 1_fix, -10_fix);
expect_eq(1_fix / 2_fix, 0.5_fix);
expect_eq(1_fix / 4_fix, 0.25_fix);
expect_eq(-1_fix / 4, -0.25_fix);

expect_eq(int8_t{1} / -4_fix, -0.25_fix);
expect_eq(int16_t{1} / -4_fix, -0.25_fix);
expect_eq(int32_t{1} / -4_fix, -0.25_fix);
expect_eq(int64_t{1} / -4_fix, -0.25_fix);
expect_eq(float{1} / -4_fix, -0.25_fix);
expect_approx(double{1} / -4_fix, -0.25, 0.0000000001);

expect_eq(uint8_t{1} / -4_fix, -0.25_fix);
expect_eq(uint16_t{1} / -4_fix, -0.25_fix);
expect_eq(uint32_t{1} / -4_fix, -0.25_fix);
expect_eq(uint64_t{1} / -4_fix, -0.25_fix);

expect_eq(-1_fix / uint8_t(4), -0.25_fix);
expect_eq(-1_fix / uint16_t(4), -0.25_fix);
expect_eq(-1_fix / uint32_t(4), -0.25_fix);
expect_eq(-1_fix / uint64_t(4), -0.25_fix);

expect_eq(-1_fix / int8_t(4), -0.25_fix);
expect_eq(-1_fix / int16_t(4), -0.25_fix);
expect_eq(-1_fix / int32_t(4), -0.25_fix);
expect_eq(-1_fix / int64_t(4), -0.25_fix);

expect_eq(1 / 4_fix, 0.25_fix);

expect_eq(4 / 1_fix, 4_fix);
expect_eq(4 / 0.5_fix, 8_fix);

expect_eq(1625.625_fix / 0.625_fix, 2601_fix);

expect(test_resulting_type<fixed_t>(int64_t(1) / 1_fix));
expect(test_resulting_type<fixed_t>(1_fix / int64_t(1)));
expect(test_resulting_type<fixed_t>(uint64_t(1) / 1_fix));
expect(test_resulting_type<fixed_t>(1_fix / uint64_t(1)));
expect(test_resulting_type<fixed_t>(1_fix / 1_fix));
expect(test_resulting_type<fixed_t>(1 / 1_fix));
expect(test_resulting_type<fixed_t>(1_fix / 1));
expect(test_resulting_type<fixed_t>(int16_t(1) / 1_fix));
expect(test_resulting_type<fixed_t>(1_fix / int16_t(1)));
expect(test_resulting_type<fixed_t>(uint16_t(1) / 1_fix));
expect(test_resulting_type<fixed_t>(1_fix / uint16_t(1)));
expect(test_resulting_type<fixed_t>(int8_t(1) / 1_fix));
expect(test_resulting_type<fixed_t>(1_fix / int8_t(1)));
expect(test_resulting_type<fixed_t>(uint8_t(1) / 1_fix));
expect(test_resulting_type<fixed_t>(1_fix / uint8_t(1)));
expect(test_resulting_type<fixed_t>(1.f / 1_fix));
expect(test_resulting_type<fixed_t>(1_fix / 1.f));
expect(test_resulting_type<double>(1. / 1_fix));
expect(test_resulting_type<double>(1_fix / 1.));
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
38 changes: 0 additions & 38 deletions unit_tests/include/compile_time_unit_tests.h

This file was deleted.

76 changes: 0 additions & 76 deletions unit_tests/include/division.h

This file was deleted.

36 changes: 0 additions & 36 deletions unit_tests/include/fixed_construction.h

This file was deleted.

50 changes: 0 additions & 50 deletions unit_tests/include/misc_functions.h

This file was deleted.

Loading

0 comments on commit 0e81bf6

Please sign in to comment.