swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] Exponent Operator


From: Russell Standish
Subject: Re: [Swarm-Support] Exponent Operator
Date: Sat, 15 Oct 2005 07:39:38 +1000
User-agent: Mutt/1.4i

On Fri, Oct 14, 2005 at 07:12:57PM +0200, Pietro Terna wrote:
>         You have to use the function power() of the C language.

There is no "power()" in C, only pow(). Note that with pow(x,y), y is
a double precision number, so basically pow(x,y)=exp(y*log(x)), which
is a very slow way of doing things, particularly if y is an integer,
or x is a power of 2.

K & R say that pow(x,n) where n is integer and x<0 is legal, so pow
must test for integerness of n - but adds extra overhead. In C++,
function overloading allows a pow(double,int) and pow(double,double)
function to be separate, so the overhead is avoided.

If n is a small integer, you are better off inlining the code
manually, eg:

  r=x+3;
  r3=r*r*r;
  r9=r3*r3*r3;

Cheers

> 
>         The best, Pietro
> 
> At 17.11 14/10/2005, you wrote:
> >Could someone tell me what the exponent operator is in ObjC, 
> >i.e.  for something like (x + 3) ^2?  Many thanks -
> >Crile
> >_______________________________________________
> >Support mailing list
> >address@hidden
> >http://www.swarm.org/mailman/listinfo/support
> 
> _______________________________________________
> Support mailing list
> address@hidden
> http://www.swarm.org/mailman/listinfo/support

-- 
*PS: A number of people ask me about the attachment to my email, which
is of type "application/pgp-signature". Don't worry, it is not a
virus. It is an electronic signature, that may be used to verify this
email came from me if you have PGP or GPG installed. Otherwise, you
may safely ignore this attachment.

----------------------------------------------------------------------------
A/Prof Russell Standish                  Phone 8308 3119 (mobile)
Mathematics                                    0425 253119 (")
UNSW SYDNEY 2052                         address@hidden             
Australia                                http://parallel.hpc.unsw.edu.au/rks
            International prefix  +612, Interstate prefix 02
----------------------------------------------------------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]