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