Computing H100000. Where did I goof ? I am puzzled

Let it all hang out

Computing H100000. Where did I goof ? I am puzzled

PostPosted by FDA OSInet » Sun Jun 05, 2016 3:32 pm

Wanting to compare the execution times of H1000000 in both NARS2000 and C on a Core i7 4970, I wrote this and got that result :


z←⎕t ⋄ +/÷⍳1000000 ⋄ ⎕t-z
14.39272672
0.03502806271


#include <stdio.h>
#include <time.h>
int main()
{
int i; float s = 0.;
for (i=1; i<=1000000;++i) s+=1./i;
printf("%20.4f \n", s);
return 0;
}


14.3574

Process returned 0 (0x0) execution time : 0.010 s
Press any key to continue.

The good news are of course that on this particular example, the execution time ratio is only 3.5 to 1.

The bad news seem that we do not get the same computation result at all :shock:

Did I good somewhere ? I cannot believe that rounding errors explain such a difference.

Any hint ?

FDA, puzzled.
FDA OSInet
 
Posts: 24
Joined: Sun Aug 30, 2015 5:07 am

Re: Computing H100000. Where did I goof ? I am puzzled

PostPosted by FDA OSInet » Sun Jun 05, 2016 9:37 pm

OK, it was a precision problem, it seems.

Changing my C program to :

#include <stdio.h>
int main()
{
int i; double s = 0.;
for (i=1; i<=1000000;++i) s+=1./i;
printf("%20.8lf \n", s);
return 0;
}

I am getting :

14.39272672

Process returned 0 (0x0) execution time : 0.010 s
Press any key to continue.
FDA OSInet
 
Posts: 24
Joined: Sun Aug 30, 2015 5:07 am


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron