Thread overview
Possibly problem with 'real'
Jul 01, 2003
Steve Adams
Jul 01, 2003
Burton Radons
Jul 01, 2003
Steve Adams
July 01, 2003
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 );
}



July 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.

July 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.
>