| Thread overview | |||||
|---|---|---|---|---|---|
|
July 01, 2003 Possibly problem with 'real' | ||||
|---|---|---|---|---|
| ||||
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 Re: Possibly problem with 'real' | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steve Adams | 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 Re: Possibly problem with 'real' | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | 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. > | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply