Date: Fri, 9 Jan 1998 16:35:34 +0100 (MET) From: Dirk-Willem van Gulik <Dirk.vanGulik@jrc.it> To: Yingjun He <hey@tuns.ca> Cc: questions@FreeBSD.ORG Subject: Re: your mail Message-ID: <Pine.SOL.3.96.980109161654.8962C-100000@elect6.jrc.it> In-Reply-To: <3.0.1.32.19980109091508.00969330@newton.ccs.tuns.ca>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 9 Jan 1998, Yingjun He wrote: > I am running FreeBSD2.25 and 2.05 and I found that the numerical calculation > results of the same program is different. Is this caused by the difference of > the operating systems? Or something wrong with my hardware? Most propably not; it is not uncommon for numerical calculation to be somewhat unstable. After many iterations a very small difference, well below the accuracy margnin propagates through. Check out for example 'Numerical Reciepes' for a good discussion. As an example consider the output of the programme below; a small conceptual thing, the order of the loop, not the formula, causes an increduble difference. Such a difference can by caused by compiler optimizations and couldless other small things. D1=1235325026304.000000 D2=1235334987776.000000 Dw. int main( int a, char * * b) { float d; int i; #define M 10000000 printf("start\n"); d=1234567890123.0; for( i=1; i <M; i++) d += 1.0*i/(1+i*i); printf("D1=%f\n",d); d=1234567890123.0; for( i=M-1; i >0; i--) d += 1.0*i/(1+i*i); printf("D2=%f\n",d); exit(0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SOL.3.96.980109161654.8962C-100000>