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
......@@ -193,25 +193,35 @@ namespace core
//\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
// 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
// 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;
......
......@@ -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