FPFlushDenormalsTest.cpp 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #ifndef JPH_CPU_WASM
  8. // Implemented as a global atomic so the compiler can't optimize it to a constant
  9. extern atomic<float> TestFltMin;
  10. atomic<float> TestFltMin = FLT_MIN;
  11. TEST_SUITE("FlushDenormalsTests")
  12. {
  13. TEST_CASE("TestFlushDenormals")
  14. {
  15. // By default flush denormals should be off
  16. {
  17. float value = TestFltMin * 0.1f;
  18. CHECK(value > 0.0f);
  19. }
  20. // Turn flush denormal on
  21. {
  22. FPFlushDenormals flush_denormals;
  23. float value = TestFltMin * 0.1f;
  24. CHECK(value == 0.0f);
  25. }
  26. // Check if state was properly restored
  27. {
  28. float value = TestFltMin * 0.1f;
  29. CHECK(value > 0.0f);
  30. }
  31. // Update TestFltMin to prevent the compiler from optimizing away TestFltMin and replace all calculations above with 0
  32. TestFltMin = 1.0f;
  33. }
  34. }
  35. #endif // JPH_CPU_WASM