Permalink
Browse files

cleanup: move abs(int64_t) to MathUtils.h

  • Loading branch information...
CrystalP committed Feb 2, 2011
1 parent 83d67e4 commit 6bfc8b0b331bd36ef19fb39ed16d8c4903b0e608
Showing with 8 additions and 11 deletions.
  1. +2 −11 xbmc/rendering/gl/RenderSystemGL.cpp
  2. +6 −0 xbmc/utils/MathUtils.h
@@ -30,7 +30,7 @@
#include "utils/log.h"
#include "utils/TimeUtils.h"
#include "utils/SystemInfo.h"
-
+#include "utils/MathUtils.h"
CRenderSystemGL::CRenderSystemGL() : CRenderSystemBase()
{
@@ -260,15 +260,6 @@ bool CRenderSystemGL::IsExtSupported(const char* extension)
return m_RenderExtensions.find(name) != std::string::npos;;
}
-#ifndef _WIN32
-static int64_t abs(int64_t a)
-{
- if(a < 0)
- return -a;
- return a;
-}
-#endif
-
bool CRenderSystemGL::PresentRender()
{
if (!m_bRenderCreated)
@@ -306,7 +297,7 @@ bool CRenderSystemGL::PresentRender()
diff = curr - m_iSwapStamp;
m_iSwapStamp = curr;
- if (abs(diff - m_iSwapRate) < abs(diff))
+ if (MathUtils::abs(diff - m_iSwapRate) < MathUtils::abs(diff))
CLog::Log(LOGDEBUG, "%s - missed requested swap",__FUNCTION__);
}
View
@@ -134,13 +134,19 @@ namespace MathUtils
return (i);
}
+ inline int64_t abs(int64_t a)
+ {
+ return (a < 0) ? -a : a;
+ }
+
inline void hack()
{
// stupid hack to keep compiler from dropping these
// functions as unused
MathUtils::round_int(0.0);
MathUtils::truncate_int(0.0);
MathUtils::ceil_int(0.0);
+ MathUtils::abs(0);
}
} // namespace MathUtils

4 comments on commit 6bfc8b0

sitzm replied Feb 2, 2011

with your changes, linux does not compile anymore with the follwing error:
In file included from karaokelyrics.cpp:26:
/home/c18103/src/test/xbmc-11.00git20110202.6bfc8b0/xbmc/utils/MathUtils.h:137: error: ‘int64_t’ does not name a type
/home/c18103/src/test/xbmc-11.00
git20110202.6bfc8b0/xbmc/utils/MathUtils.h: In function ‘void MathUtils::hack()’:
/home/c18103/src/test/xbmc-11.00~git20110202.6bfc8b0/xbmc/utils/MathUtils.h:149: error: ‘abs’ is not a member of ‘MathUtils’
make[2]: *** [karaokelyrics.o] Error 1

This can be fixed with including stdint.h in MathUtils.h

Member

mkortstiege replied Feb 2, 2011

Fixed in fadf1cd

Member

bobo1on1 replied Feb 2, 2011

Why not make abs a template function instead.

Contributor

CrystalP replied Feb 4, 2011

Why the effort? System libraries already have abs() for most interesting types. This one is the exception.
Seems to me the function belongs to some linux-specific header. MSVC already has the function.

Please sign in to comment.