TrigonometryTests.cpp 742 B

123456789101112131415161718192021222324252627
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include "UnitTestFramework.h"
  5. #include <Jolt/Math/Trigonometry.h>
  6. TEST_SUITE("TrigonometryTests")
  7. {
  8. TEST_CASE("TestACosApproximate")
  9. {
  10. // Check error over entire range [-1, 1]
  11. for (int i = -1000; i <= 1000; i++)
  12. {
  13. float x = float(i) / 1000.0f;
  14. float acos1 = acos(x);
  15. float acos2 = ACosApproximate(x);
  16. CHECK_APPROX_EQUAL(acos1, acos2, 4.3e-3f);
  17. }
  18. // Check edge cases for exact matches
  19. CHECK(ACosApproximate(1.0f) == 0.0f);
  20. CHECK(ACosApproximate(1.0e-12f) == JPH_PI / 2);
  21. CHECK(ACosApproximate(-1.0e-12f) == JPH_PI / 2);
  22. CHECK(ACosApproximate(-1.0f) == JPH_PI);
  23. }
  24. }