From 6e6a94a6af4b53d72646324659608edf2a13c256 Mon Sep 17 00:00:00 2001 From: Anonimus Date: Wed, 1 Oct 2025 10:08:57 -0400 Subject: [PATCH] Add fixed-point math parity test Makes sure the more complex functions match regardless of bitdepth Currently (and very likely to stay) only FixedSqrt --- src/console.c | 1 + src/console.h | 1 + src/d_main.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/src/console.c b/src/console.c index 6acf3e205..87c3a3e1e 100644 --- a/src/console.c +++ b/src/console.c @@ -1654,6 +1654,7 @@ static const char *CON_LoadingStrings[LOADED_ALLDONE+1] = "Init rendering daemon...", //LOADED_RINIT "Init audio subsystem...", //LOADED_SINITSFXCHANNELS "Cache HUD...", //LOADED_STINIT + "Test fixed-point arithmetic...", //LOADED_MATHINIT "Init ACSVM...", //LOADED_ACSINIT "Check game status...", //LOADED_DCHECKNETGAME "Now starting..." diff --git a/src/console.h b/src/console.h index d10aeacdd..fb2f5827c 100644 --- a/src/console.h +++ b/src/console.h @@ -52,6 +52,7 @@ typedef enum LOADED_RINIT, LOADED_SINITSFXCHANNELS, LOADED_STINIT, + LOADED_MATHINIT, LOADED_ACSINIT, LOADED_DCHECKNETGAME, LOADED_ALLDONE = LOADED_DCHECKNETGAME, diff --git a/src/d_main.cpp b/src/d_main.cpp index 111490711..79a6f9d80 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1814,6 +1814,61 @@ void D_SRB2Main(void) ST_Init(); CON_SetLoadingProgress(LOADED_STINIT); + CONS_Printf("FixedSqrt of 32767 fracunits: %d; FixedSqrt64: %d\n", + FixedSqrt(0x7FFF0000), + FixedSqrt64(0x7FFF0000)); + + if (FixedSqrt(0x7FFF0000) == FixedSqrt64(0x7FFF0000)) + { + CONS_Printf("\x83" "32767: Test OK!" "\x80" "\n"); + } + else + { + CONS_Printf("\x85" "32767: Test NG!" "\x80" "\n"); + } + + CONS_Printf("FixedSqrt of 4 fracunits: %d; FixedSqrt64: %d\n", + FixedSqrt(0x40000), + FixedSqrt64(0x40000)); + + if (FixedSqrt(0x40000) == FixedSqrt64(0x40000)) + { + CONS_Printf("\x83" "4: Test OK!" "\x80" "\n"); + } + else + { + CONS_Printf("\x85" "4: Test NG!" "\x80" "\n"); + } + + // You should probably generate the weird number with RANDOM.org +#define WEIRDNUMBER 3886284 /* 59.3 fracunits; this should approximate to around 7 */ + CONS_Printf("FixedSqrt of 59.3 fracunits: %d; FixedSqrt64: %d\n", + FixedSqrt(WEIRDNUMBER), + FixedSqrt64(WEIRDNUMBER)); + + if (FixedSqrt(WEIRDNUMBER) == FixedSqrt64(WEIRDNUMBER)) + { + CONS_Printf("\x83" "59.3: Test OK!" "\x80" "\n"); + } + else + { + CONS_Printf("\x85" "59.3: Test NG!" "\x80" "\n"); + } +#undef WEIRDNUMBER + + CONS_Printf("FixedSqrt64 of 65535 fracunits: %d (not possible at 32-bit scale)\n", + FixedSqrt64(0xFFFFFFFF)); + + CONS_Printf("IntSqrt of 32767: %d; IntSqrt64: %d\n", + IntSqrt(0x7FFF), + IntSqrt64(0x7FFF)); + + CONS_Printf("IntSqrt of 4: %d; IntSqrt64: %d\n", + IntSqrt(4), + IntSqrt64(4)); + + CON_SetLoadingProgress(LOADED_MATHINIT); + CONS_Printf("ACS_Init(): Init Action Code Script VM.\n"); ACS_Init(); CON_SetLoadingProgress(LOADED_ACSINIT);