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
//! Rounding error constant often used when comparing f32 values.
const s32 ROUNDING_ERROR_S32 = 0;
#ifdef __IRR_HAS_S64
#ifdef __IRR_HAS_S64
const s64 ROUNDING_ERROR_S64 = 0;
#endif
const f32 ROUNDING_ERROR_f32 = 0.000001f;
......@@ -188,36 +188,46 @@ namespace core
{
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).
//\result true when numbers have a ULP <= maxUlpDiff AND have the same sign.
inline bool equalsByUlp(f32 a, f32 b, int maxUlpDiff)
{
// Based on the ideas from Bruce Dawson on
// http://www.altdevblogaday.com/2012/02/22/comparing-floating-point-numbers-2012-edition/
// Based on the ideas and code from Bruce Dawson on
// 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
// 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.
int ia = *reinterpret_cast<int*>(&a);
int ib = *reinterpret_cast<int*>(&b);
union Float_t
{
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.
if ( (ia >> 31 != 0) != (ib >> 31 != 0) )
if ( fa.sign() != fb.sign() )
{
// Check for equality to make sure +0==-0
if (a == b)
if (fa.i == fb.i)
return true;
return false;
}
// Find the difference in ULPs.
int ulpsDiff = abs_(ia - ib);
int ulpsDiff = abs_(fa.i- fb.i);
if (ulpsDiff <= maxUlpDiff)
return true;
return false;
}
}
#if 0
//! returns if a equals b, not using any rounding tolerance
inline bool equals(const s32 a, const s32 b)
......@@ -243,7 +253,7 @@ namespace core
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
inline bool equals(const s64 a, const s64 b, const s64 tolerance = ROUNDING_ERROR_S64)
{
......@@ -281,7 +291,7 @@ namespace core
return a <= tolerance;
}
#ifdef __IRR_HAS_S64
#ifdef __IRR_HAS_S64
//! returns if a equals zero, taking rounding errors into account
inline bool iszero(const s64 a, const s64 tolerance = 0)
{
......@@ -470,13 +480,13 @@ namespace core
return static_cast<s32>(squareroot(static_cast<f32>(f)));
}
#ifdef __IRR_HAS_S64
#ifdef __IRR_HAS_S64
// calculate: sqrt ( x )
REALINLINE s64 squareroot(const s64 f)
{
return static_cast<s64>(squareroot(static_cast<f64>(f)));
}
#endif
#endif
// calculate: 1 / sqrt ( x )
REALINLINE f64 reciprocal_squareroot(const f64 x)
......
......@@ -104,7 +104,7 @@ static bool testCalculation_strtol(const char * valueString)
{
const s32 newFastValue = 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",
valueString, newFastValue, oldFastValue, strtolValue);
......@@ -155,6 +155,7 @@ bool test_fast_atof(void)
return false;
}
#ifndef _DEBUG // it's only faster in release
IrrlichtDevice* device = createDevice(video::EDT_NULL);
if (!device)
return false;
......@@ -192,6 +193,7 @@ bool test_fast_atof(void)
logTestString("The fast method is slower than atof()\n");
return false;
}
#endif // #ifndef _DEBUG
return true;
}
......@@ -234,6 +236,7 @@ bool test_strtol(void)
return false;
}
#ifndef _DEBUG // it's only faster in release
IrrlichtDevice* device = createDevice(video::EDT_NULL);
if (!device)
return false;
......@@ -271,6 +274,7 @@ bool test_strtol(void)
logTestString("The fast method is slower than strtol()\n");
return false;
}
#endif // #ifndef _DEBUG
return true;
}
......
Tests finished. 1 test of 1 passed.
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 @@
<Add directory="../lib/Linux/" />
</Linker>
</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>
<Compiler>
<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