Wednesday, March 28, 2012

LOG function ... what base, really?

Okay, im a little . I just read the doc for the LOG function, and it
says that LOG uses base 2.
So i figured okay, LOG(8) = 3, right? cuz 2 ^ 3 = 4. Well, wrong! According
to SQL server, LOG(8) is
not 3, but rather 2.0794415416798357.
So i thought maybe my memory of the logarithm function was wrong, looked it
up, no, im right.
Just to verify, i checked LOG10(100), which yielded 2, just like i expected.
So... Obviously, LOG is not really working in base 2 as the doc says.
Otherwise LOG(8) would = 3.
So what base DOES the LOG function really work in?
Is there a generic function in SQL Server anywhere i could call
SOME_LOG_FUNC(x, y) where i can
pass it the operand, and the actual base i want to use, so i can get a true
base 2 log?
Thanks in advance,
- Aaron.It is not base 2, it is natural logarithm (base e).
http://mathworld.wolfram.com/NaturalLogarithm.html
AMB
"Arthur Dent" wrote:

> Okay, im a little . I just read the doc for the LOG function, and
it
> says that LOG uses base 2.
> So i figured okay, LOG(8) = 3, right? cuz 2 ^ 3 = 4. Well, wrong! Accordin
g
> to SQL server, LOG(8) is
> not 3, but rather 2.0794415416798357.
> So i thought maybe my memory of the logarithm function was wrong, looked i
t
> up, no, im right.
> Just to verify, i checked LOG10(100), which yielded 2, just like i expecte
d.
> So... Obviously, LOG is not really working in base 2 as the doc says.
> Otherwise LOG(8) would = 3.
> So what base DOES the LOG function really work in?
> Is there a generic function in SQL Server anywhere i could call
> SOME_LOG_FUNC(x, y) where i can
> pass it the operand, and the actual base i want to use, so i can get a tru
e
> base 2 log?
> Thanks in advance,
> - Aaron.
>
>|||<ms:doc>
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. </ms:doc>I thought Natural Log (ln) was base-e, but then they
said it uses base-2. Thanks for clearing them up.
Is there any intrinsic way to get the base-2 log, as opposed to having to
write a whole log function myself?
Thanks -
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com>
wrote in message news:6E1E8526-DD23-4F54-8615-ACC017DAD136@.microsoft.com...
> It is not base 2, it is natural logarithm (base e).
> http://mathworld.wolfram.com/NaturalLogarithm.html
> AMB|||"LOG2(8)" = LOG(8)/LOG(2) (= LOG10(8)/LOG10(2) )
Something I still remember from those math lessons :-)
Jacco Schalkwijk
SQL Server MVP
"Arthur Dent" <hitchhikersguideto-news@.yahoo.com> wrote in message
news:%23LiDgkXUFHA.1148@.tk2msftngp13.phx.gbl...
> Okay, im a little . I just read the doc for the LOG function, and
> it says that LOG uses base 2.
> So i figured okay, LOG(8) = 3, right? cuz 2 ^ 3 = 4. Well, wrong!
> According to SQL server, LOG(8) is
> not 3, but rather 2.0794415416798357.
> So i thought maybe my memory of the logarithm function was wrong, looked
> it up, no, im right.
> Just to verify, i checked LOG10(100), which yielded 2, just like i
> expected.
> So... Obviously, LOG is not really working in base 2 as the doc says.
> Otherwise LOG(8) would = 3.
> So what base DOES the LOG function really work in?
> Is there a generic function in SQL Server anywhere i could call
> SOME_LOG_FUNC(x, y) where i can
> pass it the operand, and the actual base i want to use, so i can get a
> true base 2 log?
> Thanks in advance,
> - Aaron.
>|||You can express log x in base 2 as log(x) in base e divided by log(2) in bas
e
e.
Example:
select log(8) / log(2)
go
Result:
3.0
AMB
"Arthur Dent" wrote:

> <ms:doc>
> Comparing LOG and LOG10 The LOG function returns the natural logarit
hm
> for the given float expression. Natural logarithms are calculated by
> using the base-2 system. However, the LOG10 function returns the base-
10
> logarithm. </ms:doc>I thought Natural Log (ln) was base-e, but then they
> said it uses base-2. Thanks for clearing them up.
> Is there any intrinsic way to get the base-2 log, as opposed to having to
> write a whole log function myself?
> Thanks -
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com>
> wrote in message news:6E1E8526-DD23-4F54-8615-ACC017DAD136@.microsoft.com..
.
>
>|||In general, way to get log to any base is DIvide Ln(x) by Ln(BAse)
Log (x) = ln(x) / ln(b)
b
"Arthur Dent" wrote:

> <ms:doc>
> Comparing LOG and LOG10 The LOG function returns the natural logarit
hm
> for the given float expression. Natural logarithms are calculated by
> using the base-2 system. However, the LOG10 function returns the base-
10
> logarithm. </ms:doc>I thought Natural Log (ln) was base-e, but then they
> said it uses base-2. Thanks for clearing them up.
> Is there any intrinsic way to get the base-2 log, as opposed to having to
> write a whole log function myself?
> Thanks -
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com>
> wrote in message news:6E1E8526-DD23-4F54-8615-ACC017DAD136@.microsoft.com..
.
>
>|||Cool, thanks.
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
news:5A87B59F-5CD6-43DD-AADE-9C4E7E3F160C@.microsoft.com...
> In general, way to get log to any base is DIvide Ln(x) by Ln(BAse)
> Log (x) = ln(x) / ln(b)
> b
> "Arthur Dent" wrote:
>|||I've always been a Math g, (Not a CS major), and the depth of really
,
totally mysterious stuff embedded in the number e has always astounded me..
(do I really sound like a g now!
The formula
Log (x) = ln(x) / ln(b)
b
is just one bit, the one I like the most is the formula that contains the
five most BASIC numbers in Mathmatics, and relates them to one another. It
is totally proven, and totally incomprehensible (NoOne really understand why
it should be true)

e - 1 = 0
where i = SquareRoot (-1) and
the 'n' = PI (3.1415926535897931)
"Arthur Dent" wrote:

> Cool, thanks.
>
> "CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
> news:5A87B59F-5CD6-43DD-AADE-9C4E7E3F160C@.microsoft.com...
>
>|||It is doing the ln() function, but in floating point binary numbers.
You are not crazy.
Google the IEEE floating point Standard for a few websites with the
details. There is a difference in the Standards between REAL and FLOAT
that will figure into this if you get on a different SQL, too.
If you really want accuracy, then you can look up some assembly or C
routines that will use binary shift operations to do this. It ain't
usually worth it. use ln(x)/ln(2) and replace the function call with a
constant:
log(2) = 0.69314718055994530941723212145818

No comments:

Post a Comment