Re: why use pow(x, 2)?
Re: why use pow(x, 2)?
- Subject: Re: why use pow(x, 2)?
- From: Luke the Hiesterman <email@hidden>
- Date: Mon, 2 Nov 2009 11:37:18 -0800
On Nov 2, 2009, at 11:25 AM, Ed Wynne wrote:
On Mon, Nov 2, 2009 at 2:07 PM, Jens Alfke <email@hidden> wrote:
On Nov 2, 2009, at 11:01 AM, Chunk 1978 wrote:
why use this:
float dist = pow(red - r, 2) + pow(green - g, 2) + pow(blue - b, 2);
instead of:
float dist = ((red - r) * 2) + ((green - g) * 2) + ((blue - b) *
2);
Um, "*" is multiplication, not exponentiation. Maybe you're
thinking of the
"**" operator found in some languages, though not in C :)
That said, the original question is a good one. Using x*x instead of
pow(x,2)
would be quite a bit faster, so except for clarity reasons, there
isn't a good
reason to use pow() in that case.
Would it really be that much faster? I don't know exactly how pow() is
implemented, but I assume it's basically just a loop of
multiplications, in which case it would basically be the same as x*x
in this case, since it would exit after the first iteration....
Luke
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden