//==========================================================================
// Test calculation.
//
// Generates an array of random FP values and then repeatedly applies
// a calculation to them and checks that the same result is reached
// each time. The calculation, in the macro CALC, is intended to make
// maximum use of the FPU registers. However, the i386 compiler
// doesn't let this expression get very complex before it starts
// spilling values out to memory.
Surely it's only a good test once we're sure we've spilled some :-).
Perhaps we should have a few more to cover non-x86 FP too (a check we
haven't screwed up and missed off FP registers for example).static void do_test( double *values,
int count,
int loops,
char *name)
{
int i, j;
double sum = 1.0;
double last_sum;
unsigned int seed;
#define V(__i) (values[(__i)%count])
#define CALC ((V(i-1)*V(i+1))*(V(i-2)*V(i+2))*(V(i-3)*sum))
seed = ((unsigned int)&i)*loops*count;
// Set up an array of values...
for( i = 0; i < count; i++ )
values[i] = (double)rand( &seed )/(double)0x7fffffff;
Hmm... I'm not sure that any calculation on a NaN is necessarily
deterministic? e.g. the exponent could be set to 2047 in the result
register and the sign or mantissa left untouched from the previous
operation in that register, which may make the absolute value not be
deterministic.