Commit e33c2c5a authored by cutealien's avatar cutealien

- equalsByUlp rewritten slightly to compile with our gcc release settings without warnings.

- fast_atof tests now running on 64-bit (should've been last 64-bit specific trouble in tests).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4180 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 833ad991
...@@ -39,7 +39,7 @@ namespace core ...@@ -39,7 +39,7 @@ 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 #ifdef __IRR_HAS_S64
const s64 ROUNDING_ERROR_S64 = 0; const s64 ROUNDING_ERROR_S64 = 0;
#endif #endif
const f32 ROUNDING_ERROR_f32 = 0.000001f; const f32 ROUNDING_ERROR_f32 = 0.000001f;
...@@ -188,36 +188,46 @@ namespace core ...@@ -188,36 +188,46 @@ namespace core
{ {
return (a + tolerance >= b) && (a - tolerance <= b); return (a + tolerance >= b) && (a - tolerance <= b);
} }
//! We compare the difference in ULP's (spacing between floating-point numbers, aka ULP=1 means there exists no float between). //! We compare the difference in ULP's (spacing between floating-point numbers, aka ULP=1 means there exists no float between).
//\result true when numbers have a ULP <= maxUlpDiff AND have the same sign. //\result true when numbers have a ULP <= maxUlpDiff AND have the same sign.
inline bool equalsByUlp(f32 a, f32 b, int maxUlpDiff) inline bool equalsByUlp(f32 a, f32 b, int maxUlpDiff)
{ {
// Based on the ideas from Bruce Dawson on // Based on the ideas and code from Bruce Dawson on
// http://www.altdevblogaday.com/2012/02/22/comparing-floating-point-numbers-2012-edition/ // http://www.altdevblogaday.com/2012/02/22/comparing-floating-point-numbers-2012-edition/
// When floats are interpreted as integers the two nearest possible float numbers differ just // When floats are interpreted as integers the two nearest possible float numbers differ just
// by one integer number. Also works the other way round, an integer of 1 interpreted as float // by one integer number. Also works the other way round, an integer of 1 interpreted as float
// is for example the smallest possible float number. // is for example the smallest possible float number.
int ia = *reinterpret_cast<int*>(&a); union Float_t
int ib = *reinterpret_cast<int*>(&b); {
Float_t(float f1 = 0.0f) : f(f1) {}
// Portable sign-extraction
bool sign() const { return (i >> 31) != 0; }
int i;
float f;
};
Float_t fa(a);
Float_t fb(b);
// Different signs, we could maybe get difference to 0, but so close to 0 using epsilons is better. // Different signs, we could maybe get difference to 0, but so close to 0 using epsilons is better.
if ( (ia >> 31 != 0) != (ib >> 31 != 0) ) if ( fa.sign() != fb.sign() )
{ {
// Check for equality to make sure +0==-0 // Check for equality to make sure +0==-0
if (a == b) if (fa.i == fb.i)
return true; return true;
return false; return false;
} }
// Find the difference in ULPs. // Find the difference in ULPs.
int ulpsDiff = abs_(ia - ib); int ulpsDiff = abs_(fa.i- fb.i);
if (ulpsDiff <= maxUlpDiff) if (ulpsDiff <= maxUlpDiff)
return true; return true;
return false; return false;
} }
#if 0 #if 0
//! returns if a equals b, not using any rounding tolerance //! returns if a equals b, not using any rounding tolerance
inline bool equals(const s32 a, const s32 b) inline bool equals(const s32 a, const s32 b)
...@@ -243,7 +253,7 @@ namespace core ...@@ -243,7 +253,7 @@ namespace core
return (a + tolerance >= b) && (a - tolerance <= b); return (a + tolerance >= b) && (a - tolerance <= b);
} }
#ifdef __IRR_HAS_S64 #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)
{ {
...@@ -281,7 +291,7 @@ namespace core ...@@ -281,7 +291,7 @@ namespace core
return a <= tolerance; return a <= tolerance;
} }
#ifdef __IRR_HAS_S64 #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)
{ {
...@@ -470,13 +480,13 @@ namespace core ...@@ -470,13 +480,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 #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 #endif
// calculate: 1 / sqrt ( x ) // calculate: 1 / sqrt ( x )
REALINLINE f64 reciprocal_squareroot(const f64 x) REALINLINE f64 reciprocal_squareroot(const f64 x)
......
...@@ -104,7 +104,7 @@ static bool testCalculation_strtol(const char * valueString) ...@@ -104,7 +104,7 @@ static bool testCalculation_strtol(const char * valueString)
{ {
const s32 newFastValue = strtol10(valueString); const s32 newFastValue = strtol10(valueString);
const s32 oldFastValue = old_strtol10(valueString); const s32 oldFastValue = old_strtol10(valueString);
const s32 strtolValue = (s32)strtol(valueString, 0, 10); const s32 strtolValue = (s32)clamp(strtol(valueString, 0, 10), (long int)INT_MIN, (long int)INT_MAX);
logTestString("\n String '%s'\n New fast %d\n Old fast %d\n strtol %d\n", logTestString("\n String '%s'\n New fast %d\n Old fast %d\n strtol %d\n",
valueString, newFastValue, oldFastValue, strtolValue); valueString, newFastValue, oldFastValue, strtolValue);
...@@ -155,6 +155,7 @@ bool test_fast_atof(void) ...@@ -155,6 +155,7 @@ bool test_fast_atof(void)
return false; return false;
} }
#ifndef _DEBUG // it's only faster in release
IrrlichtDevice* device = createDevice(video::EDT_NULL); IrrlichtDevice* device = createDevice(video::EDT_NULL);
if (!device) if (!device)
return false; return false;
...@@ -192,6 +193,7 @@ bool test_fast_atof(void) ...@@ -192,6 +193,7 @@ bool test_fast_atof(void)
logTestString("The fast method is slower than atof()\n"); logTestString("The fast method is slower than atof()\n");
return false; return false;
} }
#endif // #ifndef _DEBUG
return true; return true;
} }
...@@ -234,6 +236,7 @@ bool test_strtol(void) ...@@ -234,6 +236,7 @@ bool test_strtol(void)
return false; return false;
} }
#ifndef _DEBUG // it's only faster in release
IrrlichtDevice* device = createDevice(video::EDT_NULL); IrrlichtDevice* device = createDevice(video::EDT_NULL);
if (!device) if (!device)
return false; return false;
...@@ -271,6 +274,7 @@ bool test_strtol(void) ...@@ -271,6 +274,7 @@ bool test_strtol(void)
logTestString("The fast method is slower than strtol()\n"); logTestString("The fast method is slower than strtol()\n");
return false; return false;
} }
#endif // #ifndef _DEBUG
return true; return true;
} }
......
Tests finished. 1 test of 1 passed. Tests finished. 1 test of 1 passed.
Compiled as DEBUG Compiled as DEBUG
Test suite pass at GMT Sun Jun 3 20:56:51 2012 Test suite pass at GMT Tue Jun 5 15:22:10 2012
...@@ -48,6 +48,23 @@ ...@@ -48,6 +48,23 @@
<Add directory="../lib/Linux/" /> <Add directory="../lib/Linux/" />
</Linker> </Linker>
</Target> </Target>
<Target title="Linux Release">
<Option platforms="Unix;" />
<Option output="../bin/gcc/tests" prefix_auto="1" extension_auto="1" />
<Option object_output="./Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-fno-exceptions" />
<Add option="-D_IRR_STATIC_LIB_" />
</Compiler>
<Linker>
<Add library="Xxf86vm" />
<Add library="GL" />
<Add directory="../lib/Linux/" />
</Linker>
</Target>
</Build> </Build>
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment