This piece of code surveys the set of positive normal single precision floating point numbers for numerical accuracy of the fres instruction. It is intended for use with metrowerks codewarrior or GCC.

#if defined( __GNUC__)
#include <ppc_intrinsics.h>
#endif

#include <stdio.h>

int main( void )
{
unsigned int i;
double totalError = 0;
double maxError = 0;
double currentError;
float correct, estimate;

union
{
float f;
unsigned int u;
}in;

for( i = 0x00800000UL; i < 0x7F800000; i++ )
{
in.u = i;

correct = 1.0f / in.f;
estimate = __fres( in.f );

currentError = fabs( 1.0 - (double) estimate / (double) correct );
totalError += currentError;
if( currentError > maxError )
maxError = currentError;

if( 0 == (i & 0x007FFFFF))
{
printf(".");
fflush( stdout );
}
}

totalError /= (double) ( 0x7f800000UL - 0x00800000UL);

printf( "\nmean error: 1/%g\n", 1.0/totalError );
printf( "max error: 1/%g\n", 1.0/maxError );

return 0;
}