irr::s64 now compiles with -ansi and -pendentic on gcc without warnings. Also can now be disabled completely by define.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4116 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2012-03-24 11:29:06 +00:00
parent 7b112dbce8
commit c96ab8b96e
3 changed files with 20 additions and 4 deletions

View File

@ -785,5 +785,11 @@ precision will be lower but speed higher. currently X86 only
#undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ #undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#endif #endif
//! Define __IRR_HAS_S64 if the irr::s64 type should be enable (needs long long, available on most platforms, but not part of ISO C++ 98)
#define __IRR_HAS_S64
#ifdef NO__IRR_HAS_S64
#undef __IRR_HAS_S64
#endif
#endif // __IRR_COMPILE_CONFIG_H_INCLUDED__ #endif // __IRR_COMPILE_CONFIG_H_INCLUDED__

View File

@ -39,7 +39,9 @@ namespace core
//! Rounding error constant often used when comparing f32 values. //! Rounding error constant often used when comparing f32 values.
const s32 ROUNDING_ERROR_S32 = 0; const s32 ROUNDING_ERROR_S32 = 0;
#ifdef __IRR_HAS_S64
const s64 ROUNDING_ERROR_S64 = 0; const s64 ROUNDING_ERROR_S64 = 0;
#endif
const f32 ROUNDING_ERROR_f32 = 0.000001f; const f32 ROUNDING_ERROR_f32 = 0.000001f;
const f64 ROUNDING_ERROR_f64 = 0.00000001; const f64 ROUNDING_ERROR_f64 = 0.00000001;
@ -211,12 +213,13 @@ namespace core
return (a + tolerance >= b) && (a - tolerance <= b); return (a + tolerance >= b) && (a - tolerance <= b);
} }
#ifdef __IRR_HAS_S64
//! returns if a equals b, taking an explicit rounding tolerance into account //! returns if a equals b, taking an explicit rounding tolerance into account
inline bool equals(const s64 a, const s64 b, const s64 tolerance = ROUNDING_ERROR_S64) inline bool equals(const s64 a, const s64 b, const s64 tolerance = ROUNDING_ERROR_S64)
{ {
return (a + tolerance >= b) && (a - tolerance <= b); return (a + tolerance >= b) && (a - tolerance <= b);
} }
#endif
//! returns if a equals zero, taking rounding errors into account //! returns if a equals zero, taking rounding errors into account
inline bool iszero(const f64 a, const f64 tolerance = ROUNDING_ERROR_f64) inline bool iszero(const f64 a, const f64 tolerance = ROUNDING_ERROR_f64)
@ -248,11 +251,13 @@ namespace core
return a <= tolerance; return a <= tolerance;
} }
#ifdef __IRR_HAS_S64
//! returns if a equals zero, taking rounding errors into account //! returns if a equals zero, taking rounding errors into account
inline bool iszero(const s64 a, const s64 tolerance = 0) inline bool iszero(const s64 a, const s64 tolerance = 0)
{ {
return abs_(a) > tolerance; return abs_(a) > tolerance;
} }
#endif
inline s32 s32_min(s32 a, s32 b) inline s32 s32_min(s32 a, s32 b)
{ {
@ -435,11 +440,13 @@ namespace core
return static_cast<s32>(squareroot(static_cast<f32>(f))); return static_cast<s32>(squareroot(static_cast<f32>(f)));
} }
#ifdef __IRR_HAS_S64
// calculate: sqrt ( x ) // calculate: sqrt ( x )
REALINLINE s64 squareroot(const s64 f) REALINLINE s64 squareroot(const s64 f)
{ {
return static_cast<s64>(squareroot(static_cast<f64>(f))); return static_cast<s64>(squareroot(static_cast<f64>(f)));
} }
#endif
// calculate: 1 / sqrt ( x ) // calculate: 1 / sqrt ( x )
REALINLINE f64 reciprocal_squareroot(const f64 x) REALINLINE f64 reciprocal_squareroot(const f64 x)

View File

@ -67,14 +67,17 @@ typedef signed int s32;
#endif #endif
#ifdef __IRR_HAS_S64
//! 64 bit signed variable. //! 64 bit signed variable.
/** This is a typedef for __int64, it ensures portability of the engine. */ /** This is a typedef for __int64, it ensures portability of the engine. */
#ifdef _MSC_VER #ifdef _MSC_VER
typedef __int64 s64; typedef __int64 s64;
#elif __GNUC__
__extension__ typedef long long s64;
#else #else
typedef long long s64; typedef long long s64;
#endif #endif
#endif // __IRR_HAS_S64