From e40b255da4c472546044e467ee69fdc239d95131 Mon Sep 17 00:00:00 2001 From: CryoTheRenegade Date: Fri, 23 Oct 2026 17:02:17 -0600 Subject: [PATCH 1/2] refactor(wwmath): Compare Matrix4x4 element bits with std::bit_cast operator==(Matrix4x4, Matrix4x4) read both matrices as sixteen unsigned values through pointer casts. Read each float element and convert it with std::bit_cast instead. The comparison still uses the bits, so 0.0f and -0.0f still differ and identical NaNs are still equal. Co-Authored-By: Claude Opus 5.5 --- Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp index 0b489a40c72..b0dd172e60f 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp @@ -46,6 +46,7 @@ #include "WWLib/win.h" #include #include +#include /*********************************************************************************************** * Matrix4x4::Multiply -- Multiply two Matrix4x4's together * @@ -180,16 +181,15 @@ void Matrix4x4::Multiply(const Matrix4x4 & a,const Matrix3D & b,Matrix4x4 * res) #undef ROWCOL4 } +// Compares the bits of the elements, so 0.0f and -0.0f differ and identical NaNs are equal. int operator == (const Matrix4x4 & a, const Matrix4x4 & b) { - unsigned* m1=(unsigned*)&a; - unsigned* m2=(unsigned*)&b; unsigned res=0; for (int i=0;i<4;++i) { - res|=*m1++^*m2++; - res|=*m1++^*m2++; - res|=*m1++^*m2++; - res|=*m1++^*m2++; + res|=std::bit_cast(a[i][0])^std::bit_cast(b[i][0]); + res|=std::bit_cast(a[i][1])^std::bit_cast(b[i][1]); + res|=std::bit_cast(a[i][2])^std::bit_cast(b[i][2]); + res|=std::bit_cast(a[i][3])^std::bit_cast(b[i][3]); } return !res; } From 006c62b08dc0dd165c94820a5ce7384a04988587 Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Tue, 3 Nov 2026 11:22:47 -0700 Subject: [PATCH 2/2] refactor(wwmath): Compare Matrix4x4 bits with memcmp Co-Authored-By: Claude Opus 5.5 --- Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp index b0dd172e60f..b346825c584 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp @@ -46,7 +46,7 @@ #include "WWLib/win.h" #include #include -#include +#include /*********************************************************************************************** * Matrix4x4::Multiply -- Multiply two Matrix4x4's together * @@ -184,14 +184,7 @@ void Matrix4x4::Multiply(const Matrix4x4 & a,const Matrix3D & b,Matrix4x4 * res) // Compares the bits of the elements, so 0.0f and -0.0f differ and identical NaNs are equal. int operator == (const Matrix4x4 & a, const Matrix4x4 & b) { - unsigned res=0; - for (int i=0;i<4;++i) { - res|=std::bit_cast(a[i][0])^std::bit_cast(b[i][0]); - res|=std::bit_cast(a[i][1])^std::bit_cast(b[i][1]); - res|=std::bit_cast(a[i][2])^std::bit_cast(b[i][2]); - res|=std::bit_cast(a[i][3])^std::bit_cast(b[i][3]); - } - return !res; + return memcmp(&a, &b, sizeof(Matrix4x4)) == 0; } int operator != (const Matrix4x4 & a, const Matrix4x4 & b)