diff --git a/Source/engine.h b/Source/engine.h index 80749c25b..131cc281d 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -36,6 +36,7 @@ #include "appfat.h" #include "miniwin/miniwin.h" #include "utils/stdcompat/cstddef.hpp" +#include "utils/stdcompat/abs.h" #define TILE_WIDTH 64 #define TILE_HEIGHT 32 @@ -190,7 +191,7 @@ struct Point { constexpr friend Point abs(Point a) { - return { std::abs(a.x), std::abs(a.y) }; + return { abs(a.x), abs(a.y) }; } constexpr int ManhattanDistance(Point other) const diff --git a/Source/utils/stdcompat/abs.h b/Source/utils/stdcompat/abs.h new file mode 100644 index 000000000..cebf718a0 --- /dev/null +++ b/Source/utils/stdcompat/abs.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace devilution { + +template +constexpr T abs(const T &a) +{ +#if defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) + return std::abs(a); +#else + return (a < 0) ? -a : a; +#endif +} + +}