From: Toon Moene <toon@moene.indiv.nluug.nl>
Subject: Re: compiler efficency; OK, just one more :-)
Date: Wed, 29 Jan 97 20:25:03 +0100 [thread overview]
Message-ID: <9701291925.AA16054@moene.indiv.nluug.nl> (raw)
> 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
reply other threads:[~1997-01-29 19:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox