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!

LOG Base N... 1

Status
Not open for further replies.

rheilman

Programmer
Dec 6, 2002
51
US
I've been looking at Books Online and have found only the LOG() function (natural logarithm) and the LOG10() function (logarithm base 10). In the following section of BOL...

Comparing LOG and LOG10
The LOG function returns the natural logarithm for the given float expression. Natural logarithms are calculated by using the base-2 system. However, the LOG10 function returns the base-10 logarithm. Use both LOG and LOG10 for trigonometric applications. For example, this SELECT statement calculates both the LOG and LOG10 of the value 1.75:

...the statement that "Natural logarithms are calculated by using the base-2 system." seems misleading to me, as I thought natural logarithms were base-e. When I execute...

SELECT LOG10(POWER(10,2))

...the result is 2.0. If the base 2 thing is correct, then when I execute...

SELECT LOG(POWER(2,10))

...I would think that the result would be 10. However, the actual result is 6.9314718055994531. If this is a "DOH" thing on my part, please, tactfully set me straight.

My bottom line is that, if a "log base 2" function does not readily exist in SQL Server, can someone put on the trail of writing my own, or at least refer me to some documentation of the thing.

Thanks!
RayTheOtherRay <><

"I was going to change my shirt, but I changed my mind instead." - Winnie the Pooh
 
Log does base e (2.71828...) - opposite from EXP()

To simulate any other base (>1), use the following fact

log (N) = LOG(N)/LOG(x)
x

Or in your case:

log(1024)/log(2)

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Thanks vongrunt!

That was exactly what I wanted!

Thanks again!
RayTheOtherRay <><

"I was going to change my shirt, but I changed my mind instead." - Winnie the Pooh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top