single precision arithmetic doesn't seem to work right on a 4D/120GTX

Steve Dempsey sd%chem at UCSD.EDU
Thu Jan 26 08:58:34 AEST 1989


Environment:	IRIS 4D/120GTX running 3.1

Problem:	Single precision arithmetic fails inconsistently

Repeat by:	Running the examples below (again and again if necessary)

--------------------------cut here-----------------------------------------
#include <float.h>
/*
*	sp.c - test single precision multiplication (cc requires -float arg)
*/
main()
	{
	float	f, fsq;

	f = 1.0 + (10*FLT_EPSILON);
	fsq = f * f;
	printf("f= %9.7f, fsq= %9.7f\n", f, fsq);
	}
--------------------------cut here-----------------------------------------

Compile this code with:	cc -float sp.c -o sp
When I run this program I get one of two results:

	f= 1.0000012, fsq= 3.9999485 	or
	f= 1.0000012, fsq= 1.0000024

The wrong answer appears MUCH more frequently than the correct answer.
Try something like:	repeat 1000 sp
Every once in awhile the correct answer goes by.

If this isn't frustrating enough, try this variation:

--------------------------cut here-----------------------------------------
#include <float.h>
/*
* Loop on the single precision multiplication, printing something only when
* the correct answer is computed.
*/
main()
	{
	float	f, fsq;
	int	n;

	f = 1.0 + (10*FLT_EPSILON);
	for(n=1;;n++)
		{
		fsq = f * f;
		if( fsq < 2.0 ) printf("%d: f= %9.7f, fsq= %9.7f\n", n, f, fsq);
		}
	}
--------------------------cut here-----------------------------------------

Compile this code with:	cc -float sp2.c -o sp2

When I run this most of the time it prints nothing because the wrong value
is computed.  Usually there are several million iterations between correct
values.  The rate of correct computation seems to vary with system load as
well.

Additional notes:
	FORTRAN versions of these programs exhibit the identical results.
	Double precision has never failed for me.

Can anybody out there repeat these problems?  I've tried this on a 4D/70GT
running version 3.0 and cannot reproduce the problem there.  Do other models
of the 4D exhibit this behavior?

	Steve Dempsey
	Dept. of Chemistry Computer Facility, B-014
	University of Calif. at San Diego
	La Jolla, CA 92093
	(619) 534-0208
	INTERNET:	sdempsey at ucsd.edu
	BITNET:		sdempsey at ucsd
	UUCP:		ucsd!sdempsey



More information about the Comp.sys.sgi mailing list