From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,f8f184f3bc3517df X-Google-Attributes: gidfc89c,public X-Google-Thread: 1094ba,f8f184f3bc3517df X-Google-Attributes: gid1094ba,public X-Google-Thread: f678f,f8f184f3bc3517df X-Google-Attributes: gidf678f,public From: corbett@lupa.eng.sun.com (Robert Corbett) Subject: Re: a**2 or a*a Date: 1998/01/15 Message-ID: <69jotq$pv5@engnews1.Eng.Sun.COM>#1/1 X-Deja-AN: 317156833 References: <34BCC4A4.F27A00D1@cranfield.ac.uk> <34BCD934.41C6@bristol.ac.uk> Organization: Sun Microsystems Computer Corporation Newsgroups: comp.lang.fortran,comp.unix.osf.misc,comp.unix.programmer In article <34BCD934.41C6@bristol.ac.uk>, Arnaud Desitter wrote: >Yon Han CHONG wrote: >> >> Is there speed difference between a**2 and a*a. >> >No. A good compiler (and the digital's one is good in this respect) will >use the best algorithm for a**b, i.e. a multiplication if b=2. > >Cheers, >Arnaud While it is true that the best implementation of a**2 is a*a on most machines, there is no "best" algorithm for most of the remaining powers. Implementing a**3 as a*a*a causes the expression to have a 1 ulp error bound. Implementing it as pow(a, 3.0) will cause it to have an error bound of just over 1/2 ulp, assuming a good implementation of pow. The other integer powers that have obvious implementations are -1 and 1. The power zero has an obvious implementation that drives people who think we are doing math instead of computing nuts. Sincerely, Bob Corbett