Re: why use pow(x, 2)?
Re: why use pow(x, 2)?
- Subject: Re: why use pow(x, 2)?
- From: Jean-Daniel Dupas <email@hidden>
- Date: Mon, 2 Nov 2009 20:06:59 +0100
Le 2 nov. 2009 à 20:01, Chunk 1978 a écrit :
i just came across some code, and i'm trying to understand why the
developer
chose to use the pow() function instead of simply multiplying as the
2nd
arguments are always 2. i'm certainly no mathematician, but if the
2nd
argument is going to be 2, why use pow()? is it just a matter of
taste?
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);
I'm not sure you understand the pow function, or did you mean :
float dist = ((red - r) * (red - r)) + ((green - g) * (green - g)) +
((blue - b) * (blue - b));
-- Jean-Daniel
_______________________________________________
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