[comp.sys.transputer] Improper results on T800

choudhry@eng.umd.edu (Zafar Ullah Choudhry) (04/25/91)

/* Hi Xputer Users! I have a small program which I am trying to run on
   T800 processor. If this program is compiled for T400 processor, i.e.,
   math functions are emulated, you  get the proper results. However, if
   you compile it for T800, the results become zero. In both the cases
    the program is executed on T800. I have tried Logical C and 3L 
   compilers, both give the same results. The problem is actually with
   improper rounding off. I know one way of fixing the problem but I want
    to get the opinion from other users. Also, this problem shows up in the
     form of inaccurate results in some other types of data. Please inform
     me about your if you get a chance to try this tiny program on your
     system.

     
     THE PROGRAM PRINTS BOTH THE REQUIRED AND CALCULATED RESULTS.

                                        
					Thanks.
                                        Zafar Ullah Choudhry
                                        Email: choudhry@bagend.eng.umd.edu 
					University of Maryland, College 
					Park, USA.
*/


/* ***** Header include files. ***** */
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>


main ()
{
  int 	nsite;
  float we, weneg, freea[10], free_l[20], yin[12], xdin[10];
  float xin[10], xdpn[10], freadp[10], clongp[10], ydin[10];

	/* initialize the constants and variables */
	we      = 7.29211508E-5;     /* Earth sidereal rotation rate.           */
        weneg   = -7.29211508E-5;    /* Negative rotation rate.                 */
	nsite = 0;
	freea[8] = 0.250648; yin[nsite] = -16018765.0000;
	freea[7] = -0.968078; xdin[nsite]=1168.106812;

	/* caculate the result */
	free_l[1] = freea[8] * (we * yin[nsite] + xdin[nsite]);
	free_l[2] = freea[7] * (we * yin[nsite] + xdin[nsite]);

	printf ("The Expected Results:> free_l[1]=%f and free_l[2]=%f\n",
		 -0.000002, 0.000007);

	printf ("The Calculated Values:> free_l[1]=%f and free_l[2]=%f\n",
		 free_l[1], free_l[2]);

	printf ("Done...\n");
	exit (0);
}

AT1F@DLRVMKP.BITNET (04/26/91)

hi all,

your floating point number problem stems from limited representation
capabilities of numbers on your computer.

the resulting error comes from calculating
(we * yin&nsitea + xdin&nsitea)

we * yin&nsitea = 1168.106778
xdin&nsitea     = 1168.106812

the two numbers differ in the 8th significant digit!
IEEE says single precision handles 7 significant digits. the results
obtained are pure random.

to overcome the problem change to 'double'.

have a nice weekend.
Stefan Pokorny, DLR (german aerospace research establishment), Cologne,
                Germany
E-Mail: at1f@dlrvmkp.bitnet