From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <9701291925.AA16054@moene.indiv.nluug.nl> Date: Wed, 29 Jan 97 20:25:03 +0100 From: Toon Moene Subject: Re: compiler efficency; OK, just one more :-) > To improve numerical precision, you should start with > the smallest fractions first. I had to post this as it's > the first time I can show off all those years spent > playing Numerical Analyst... A simple change gives: If you really want to improve numerical accuracy, you have to change another bit: PROGRAM EULER DOUBLE PRECISION GAM, FAC GAM = 0.0d0 ! *** Was 1.0d0 NMAX=100000000 FAC = dble(NMAX) DO I=2,NMAX GAM=GAM+1.0d0/FAC FAC=FAC-1.0d0 ENDDO GAM = GAM - DLOG(dble(NMAX)) + 1.0d0 ! *** Add 1.0d0 WRITE(*,*) GAM WRITE(*,*) 'Exact: 0,57721566490153286060' END Oh, BTW, I got another 10 % speed up by changing: GAM = GAM - DLOG(dble(NMAX)) + 1.0d0 ! *** WRITE(*,*) GAM into WRITE(*,*) GAM - DLOG(dble(NMAX)) + 1.0d0 because that makes gcc allocate GAM in a floating point register, instead of on the stack (no, I don't know why - even on my register starved m68k this simple routine leaves 3 floating point registers unused; must be a bug^H^H^Hshortcoming in gcc's register allocation algorithm). Cheers, Toon. -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com