Skip to content

Commit

Permalink
COMMON: Add specialized templates for float ABS/MIN/MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Mar 28, 2011
1 parent 7d7e9e5 commit 2ae895c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "common/endianness.h"

#include <cmath>

#ifdef MIN
#undef MIN
#endif
Expand Down Expand Up @@ -64,6 +66,27 @@ inline uint64 NEXTPOWER2(uint64 x) {
return x + 1;
}

#ifdef HAVE_FABS
template<> inline double ABS(double x) { return fabs(x); }
#endif
#ifdef HAVE_FABSF
template<> inline float ABS(float x) { return fabsf(x); }
#endif

#ifdef HAVE_FMIN
template<> inline double MIN(double a, double b) { return fmin(a, b); }
#endif
#ifdef HAVE_FMINF
template<> inline float MIN(float a, float b) { return fminf(a, b); }
#endif

#ifdef HAVE_FMAX
template<> inline double MAX(double a, double b) { return fmax(a, b); }
#endif
#ifdef HAVE_FMAXF
template<> inline float MAX(float a, float b) { return fmaxf(a, b); }
#endif

/**
* Macro which determines the number of entries in a fixed size array.
*/
Expand Down

0 comments on commit 2ae895c

Please sign in to comment.