From 4a71dc3e4c7cd8ac65c2ee11d9553fa45d9ada5f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 5 Dec 2024 08:56:31 +0100 Subject: [PATCH] System: add common.floatExceptions.test to test floating point exceptions --- src/engine/framework/System.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/engine/framework/System.cpp b/src/engine/framework/System.cpp index a863dcbce4..cb98778339 100644 --- a/src/engine/framework/System.cpp +++ b/src/engine/framework/System.cpp @@ -71,6 +71,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. static Cvar::Cvar common_floatExceptions_overflow("common.floatExceptions.overflow", "enable floating point exception for operation producing an overflow", Cvar::INIT, false); + static Cvar::Cvar common_floatExceptions_test("common.floatExceptions.test", + "test floating point exception", + Cvar::INIT, false); #endif namespace Sys { @@ -436,6 +439,27 @@ static void SetFloatingPointExceptions() unsigned int current; _controlfp_s(¤t, exceptions, _MCW_EM); #endif + + if (common_floatExceptions_test.Get()) + { + Log::Warn("Testing of floating point exceptions:"); + + { + volatile float f = -1.0f; + Log::Warn("Computing √%.0f…", static_cast(f)); + Log::Warn("Result of √%.0f: %.0f", static_cast(f), sqrt(f)); + } + { + volatile float f = 0.0f; + Log::Warn("Computing 1÷%.0f…", static_cast(f)); + Log::Warn("Result of 1÷%.0f: %.0f", static_cast(f), 1/f); + } + { + volatile float f = std::numeric_limits::max(); + Log::Warn("Computing 2×%.0f…", static_cast(f)); + Log::Warn("Result of 2×%.0f: %.0f", static_cast(f), 2*f); + } + } #endif }