Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleanup: move abs(int64_t) to MathUtils.h

  • Loading branch information...
commit 6bfc8b0b331bd36ef19fb39ed16d8c4903b0e608 1 parent 83d67e4
@CrystalP CrystalP authored
Showing with 8 additions and 11 deletions.
  1. +2 −11 xbmc/rendering/gl/RenderSystemGL.cpp
  2. +6 −0 xbmc/utils/MathUtils.h
View
13 xbmc/rendering/gl/RenderSystemGL.cpp
@@ -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
6 xbmc/utils/MathUtils.h
@@ -134,6 +134,11 @@ 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
@@ -141,6 +146,7 @@ namespace MathUtils
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
Collaborator

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.00~git20110202.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

@mkortstiege
Collaborator

Fixed in fadf1cd

@bobo1on1
Collaborator

Why not make abs a template function instead.

@CrystalP
Collaborator

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.
Something went wrong with that request. Please try again.