2
0

FPFlushDenormalsTest.cpp 965 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include "UnitTestFramework.h"
  5. #include <Jolt/Core/FPFlushDenormals.h>
  6. #include <atomic>
  7. // Implemented as a global atomic so the compiler can't optimize it to a constant
  8. extern atomic<float> TestFltMin;
  9. atomic<float> TestFltMin = FLT_MIN;
  10. TEST_SUITE("FlushDenormalsTests")
  11. {
  12. TEST_CASE("TestFlushDenormals")
  13. {
  14. // By default flush denormals should be off
  15. {
  16. float value = TestFltMin * 0.1f;
  17. CHECK(value > 0.0f);
  18. }
  19. // Turn flush denormal on
  20. {
  21. FPFlushDenormals flush_denormals;
  22. float value = TestFltMin * 0.1f;
  23. CHECK(value == 0.0f);
  24. }
  25. // Check if state was properly restored
  26. {
  27. float value = TestFltMin * 0.1f;
  28. CHECK(value > 0.0f);
  29. }
  30. // Update TestFltMin to prevent the compiler from optimizing away TestFltMin and replace all calculations above with 0
  31. TestFltMin = 1.0f;
  32. }
  33. }