Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

log2

Status
Not open for further replies.

SurvivorTiger

Programmer
Jul 9, 2002
265
US
Hi everyone,

How can i do log2(number) in C++ ?
i thought maybe it would be part of the math.h header file...but that didn't seem to work for me...but maybe i was implementing it wrong?!

Please help!

AIM: Survivertiger
 
Code:
inline double log2(double x)
{
  static const double xxx = 1.0/log(2.0);
  return log(x)*xxx;
}
 
On some implementations ln is more efficient than log but you have to run a loop a few thousand times to find out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top