Skip to content

Commit c8abece

Browse files
committed
feat: Migrate deterministic math from fdlibm to gamemath
1 parent cd676ed commit c8abece

5 files changed

Lines changed: 33 additions & 30 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ endif()
6464

6565
include(cmake/config.cmake)
6666
include(cmake/gamespy.cmake)
67-
include(cmake/fdlibm.cmake)
67+
include(cmake/gamemath.cmake)
6868
include(cmake/lzhl.cmake)
6969

7070
if (IS_VS6_BUILD)

Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ target_link_libraries(core_wwmath PRIVATE
8989
core_wwcommon
9090
corei_always
9191
core_wwsaveload
92-
fdlibm
92+
gamemath
9393
)
9494

9595
# @todo Test its impact and see what to do with the legacy functions.

Core/Libraries/Source/WWVegas/WWMath/wwmath.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "always.h"
4040
#include <math.h>
4141
#include <float.h>
42-
#include "fdlibm_det.h"
42+
#include "gmath.h"
4343
#include <assert.h>
4444

4545
#ifdef RETAIL_COMPATIBLE_CRC
@@ -131,16 +131,16 @@ class WWMath
131131

132132

133133
#ifdef USE_DETERMINISTIC_MATH
134-
static WWINLINE float Atan(float x) { return static_cast<float>(fdlibm_atan(x)); }
135-
static WWINLINE float Atan2(float y, float x) { return static_cast<float>(fdlibm_atan2(y, x)); }
136-
static WWINLINE float Tan(float x) { return static_cast<float>(fdlibm_tan(x)); }
137-
static WWINLINE float Sinh(float x) { return static_cast<float>(fdlibm_sinh(x)); }
138-
static WWINLINE float Cosh(float x) { return static_cast<float>(fdlibm_cosh(x)); }
139-
static WWINLINE float Tanh(float x) { return static_cast<float>(fdlibm_tanh(x)); }
140-
static WWINLINE float Exp(float x) { return static_cast<float>(fdlibm_exp(x)); }
141-
static WWINLINE float Log(float x) { return static_cast<float>(fdlibm_log(x)); }
142-
static WWINLINE float Log10(float x) { return static_cast<float>(fdlibm_log10(x)); }
143-
static WWINLINE float Pow(float x, float y) { return static_cast<float>(fdlibm_pow(x, y)); }
134+
static WWINLINE float Atan(float x) { return gm_atanf(x); }
135+
static WWINLINE float Atan2(float y, float x) { return gm_atan2f(y, x); }
136+
static WWINLINE float Tan(float x) { return gm_tanf(x); }
137+
static WWINLINE float Sinh(float x) { return gm_sinhf(x); }
138+
static WWINLINE float Cosh(float x) { return gm_coshf(x); }
139+
static WWINLINE float Tanh(float x) { return gm_tanhf(x); }
140+
static WWINLINE float Exp(float x) { return gm_expf(x); }
141+
static WWINLINE float Log(float x) { return gm_logf(x); }
142+
static WWINLINE float Log10(float x) { return gm_log10f(x); }
143+
static WWINLINE float Pow(float x, float y) { return gm_powf(x, y); }
144144
#else
145145
static WWINLINE float Atan(float x) { return static_cast<float>(atan(x)); }
146146
static WWINLINE float Atan2(float y, float x) { return static_cast<float>(atan2(y, x)); }
@@ -342,13 +342,13 @@ WWINLINE long WWMath::Float_To_Long(double f)
342342
}
343343

344344
// ----------------------------------------------------------------------------
345-
// Cos (deterministic, fdlibm)
345+
// Cos (deterministic, GameMath)
346346
// ----------------------------------------------------------------------------
347347

348348
#ifdef USE_DETERMINISTIC_MATH
349349
WWINLINE float WWMath::Cos(float val)
350350
{
351-
return (float)fdlibm_cos((double)val);
351+
return gm_cosf(val);
352352
}
353353
#else
354354
#if defined(_MSC_VER) && defined(_M_IX86)
@@ -371,13 +371,13 @@ WWINLINE float WWMath::Cos(float val)
371371
#endif
372372

373373
// ----------------------------------------------------------------------------
374-
// Sin (deterministic, fdlibm)
374+
// Sin (deterministic, GameMath)
375375
// ----------------------------------------------------------------------------
376376

377377
#ifdef USE_DETERMINISTIC_MATH
378378
WWINLINE float WWMath::Sin(float val)
379379
{
380-
return (float)fdlibm_sin((double)val);
380+
return gm_sinf(val);
381381
}
382382
#else
383383
#if defined(_MSC_VER) && defined(_M_IX86)
@@ -530,7 +530,7 @@ WWINLINE float WWMath::Fast_Acos(float val)
530530
#ifdef USE_DETERMINISTIC_MATH
531531
WWINLINE float WWMath::Acos(float val)
532532
{
533-
return (float)fdlibm_acos((double)val);
533+
return gm_acosf(val);
534534
}
535535
#else
536536
WWINLINE float WWMath::Acos(float val)
@@ -574,7 +574,7 @@ WWINLINE float WWMath::Fast_Asin(float val)
574574
#ifdef USE_DETERMINISTIC_MATH
575575
WWINLINE float WWMath::Asin(float val)
576576
{
577-
return (float)fdlibm_asin((double)val);
577+
return gm_asinf(val);
578578
}
579579
#else
580580
WWINLINE float WWMath::Asin(float val)
@@ -590,7 +590,7 @@ WWINLINE float WWMath::Asin(float val)
590590
#ifdef USE_DETERMINISTIC_MATH
591591
WWINLINE float WWMath::Sqrt(float val)
592592
{
593-
return (float)sqrt((double)val);
593+
return gm_sqrtf(val);
594594
}
595595
#else
596596
#if defined(_MSC_VER) && defined(_M_IX86)
@@ -639,7 +639,7 @@ WWINLINE int WWMath::Float_To_Int_Floor(const float& f)
639639
}
640640

641641
/// ----------------------------------------------------------------------------
642-
// Inverse square root (deterministic, portable Quake III style + fdlibm)
642+
// Inverse square root (deterministic, portable Quake III style + GameMath)
643643
// ----------------------------------------------------------------------------
644644

645645
#ifdef USE_DETERMINISTIC_MATH

cmake/fdlibm.cmake

Lines changed: 0 additions & 9 deletions
This file was deleted.

cmake/gamemath.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(GM_ENABLE_INTRINSICS OFF CACHE BOOL "Disable intrinsics for cross-arch determinism" FORCE)
2+
set(GM_ENABLE_TESTS OFF CACHE BOOL "Disable GameMath tests" FORCE)
3+
4+
FetchContent_Declare(
5+
gamemath
6+
GIT_REPOSITORY https://github.com/TheAssemblyArmada/GameMath.git
7+
GIT_TAG master
8+
)
9+
10+
FetchContent_MakeAvailable(gamemath)
11+
12+
include_directories(${gamemath_SOURCE_DIR}/include)

0 commit comments

Comments
 (0)