• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: why use pow(x, 2)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why use pow(x, 2)?


  • Subject: Re: why use pow(x, 2)?
  • From: Gregory Weston <email@hidden>
  • Date: Mon, 02 Nov 2009 17:36:45 -0500

Luke the Hiesterman wrote:

On Nov 2, 2009, at 11:25 AM, Ed Wynne wrote:

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....

The idea that pow() is too slow to be acceptable for small integer exponents is inherited knowledge. A *long* time ago it was the case that the overhead of the function call dwarfed the math of such operations *and* CPUs were slow enough that if you were doing a lot of it and you cared about performance it made sense to do it longhand.


Since then we've gotten better and tremendously faster CPUs and better compilers, but it's one of those things that some people just absorbed as a True Fact.
_______________________________________________


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


  • Prev by Date: Re: why use pow(x, 2)?
  • Next by Date: Re: why use pow(x, 2)?
  • Previous by thread: [moderator Re: why use pow(x, 2)?
  • Next by thread: Ruby Grammar for TDParseKit
  • Index(es):
    • Date
    • Thread