summaryrefslogtreecommitdiff
path: root/src/macros.h
diff options
context:
space:
mode:
authorskidd13 <skidd13@openttd.org>2007-11-19 18:58:04 +0000
committerskidd13 <skidd13@openttd.org>2007-11-19 18:58:04 +0000
commit50bfe1a19d26d99b6ee10236771bd8c7cd38be01 (patch)
tree18ac24e0b26fa3cf7cb17962dde493f142f39a03 /src/macros.h
parent8be526e4990ef8c7a742e6f3f67a42d0036750eb (diff)
downloadopenttd-50bfe1a19d26d99b6ee10236771bd8c7cd38be01.tar.xz
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
Diffstat (limited to 'src/macros.h')
-rw-r--r--src/macros.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/macros.h b/src/macros.h
index f42870f3c..e5f64c68f 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -79,6 +79,10 @@ template<typename T, typename U> static inline T AB(T& x, const uint8 s, const u
#undef max
#endif
+#ifdef abs
+#undef abs
+#endif
+
/**
* Returns the maximum of two values.
*
@@ -138,6 +142,18 @@ static inline uint minu(const uint a, const uint b)
}
/**
+ * Returns the absolute value of (scalar) variable.
+ *
+ * @note assumes variable to be signed
+ * @param a The value we want to unsign
+ * @return The unsigned value
+ */
+template <typename T> static inline T abs(T a)
+{
+ return (a < (T)0) ? -a : a;
+}
+
+/**
* Clamp an integer between an interval.
*
* This function returns a value which is between the given interval of
@@ -519,8 +535,6 @@ static inline bool CHANCE16I(const uint a, const uint b, const uint32 r)
for (_i = 0; _b != 0; _i++, _b >>= 1) \
if (_b & 1)
-#define abs myabs
-
static inline uint16 ReadLE16Aligned(const void* x)
{