Skip to content

Commit

Permalink
System: add common.floatExceptions.test to test floating point except…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
illwieckz committed Dec 5, 2024
1 parent 0d3a709 commit 4a71dc3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/engine/framework/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static Cvar::Cvar<bool> common_floatExceptions_overflow("common.floatExceptions.overflow",
"enable floating point exception for operation producing an overflow",
Cvar::INIT, false);
static Cvar::Cvar<bool> common_floatExceptions_test("common.floatExceptions.test",
"test floating point exception",
Cvar::INIT, false);
#endif

namespace Sys {
Expand Down Expand Up @@ -436,6 +439,27 @@ static void SetFloatingPointExceptions()
unsigned int current;
_controlfp_s(&current, 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<float>(f));
Log::Warn("Result of √%.0f: %.0f", static_cast<float>(f), sqrt(f));
}
{
volatile float f = 0.0f;
Log::Warn("Computing 1÷%.0f…", static_cast<float>(f));
Log::Warn("Result of 1÷%.0f: %.0f", static_cast<float>(f), 1/f);
}
{
volatile float f = std::numeric_limits<float>::max();
Log::Warn("Computing 2×%.0f…", static_cast<float>(f));
Log::Warn("Result of 2×%.0f: %.0f", static_cast<float>(f), 2*f);
}
}
#endif
}

Expand Down

0 comments on commit 4a71dc3

Please sign in to comment.