Browse Source

constexpr version of abs

pull/2113/head
Vladimir Olteanu 5 years ago committed by Anders Jenbo
parent
commit
02ffada9b8
  1. 3
      Source/engine.h
  2. 17
      Source/utils/stdcompat/abs.h

3
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

17
Source/utils/stdcompat/abs.h

@ -0,0 +1,17 @@
#pragma once
#include <algorithm>
namespace devilution {
template <typename T>
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
}
}
Loading…
Cancel
Save