D - Possibly problem with 'real'
- Steve Adams (27/27) Jul 01 2003 The program below prints
- Burton Radons (2/4) Jul 01 2003 Use "%20.14Lf" as the formatting code to print real.
- Steve Adams (3/7) Jul 01 2003 That did it, thanks.
The program below prints Finished -0.00000000000000 Finished -0.00000000000000 for the results. But, it you change all the 'real' to 'double', you correctly get: Finished 21081851083598.38281400000000 Finished 21081851083600.37499900000000 import c.stdlib; import math; int main() { long i; real sum=0.0,newsum,f; real sumerr=0.0; real err; for(i=1;i<=1000000000;i++) { f = sqrt( (real) i); newsum = sum + f; err = (newsum - sum ) - f; sumerr += err; sum = newsum; } printf("Finished %20.14f\n",sum); printf("Finished %20.14f\n",sum-sumerr); return( 0 ); }
Jul 01 2003
Steve Adams wrote:printf("Finished %20.14f\n",sum); printf("Finished %20.14f\n",sum-sumerr);Use "%20.14Lf" as the formatting code to print real.
Jul 01 2003
That did it, thanks. "Burton Radons" <loth users.sourceforge.net> wrote in message news:bds4bs$2vtm$1 digitaldaemon.com...Steve Adams wrote:printf("Finished %20.14f\n",sum); printf("Finished %20.14f\n",sum-sumerr);Use "%20.14Lf" as the formatting code to print real.
Jul 01 2003