Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Re: compiler efficency; OK, just one more :-)
@ 1997-01-29 19:25 Toon Moene
  0 siblings, 0 replies; only message in thread
From: Toon Moene @ 1997-01-29 19:25 UTC (permalink / 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-01-29 19:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-01-29 19:25 compiler efficency; OK, just one more :-) Toon Moene

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox