MathExpressions.log() and MathExpressions.ln() with SQL Server 2008 #990

Closed
janfrodeh opened this Issue Oct 6, 2014 · 7 comments

Comments

Projects
None yet
3 participants
@janfrodeh

MathExpressions.log() uses the SQL function LOG(float, base) which is not available on SQL Server 2008.

MathExpressions.ln() uses the SQL function LN(float) which is not available on SQL Server 2008.

Would using LOG(float) for natural and LOG10 for 10-base make these compatible also with SQL Server 2008?

@Shredder121

This comment has been minimized.

Show comment
Hide comment
@Shredder121

Shredder121 Oct 6, 2014

Member

Using LOG(float) for natural log would work, but MathExpressions.log() takes the base as second argument.
The only way that I think this would work, is that, under SQL Server 2008 (or wherever it also may not work) the base is ignored and only LOG10 is used.
Do you know which versions of SQL Server have the LOG(float) function? (so don't have the LOG(float, base) function)
Then we can aggregate all our findings here and resolve it.

Member

Shredder121 commented Oct 6, 2014

Using LOG(float) for natural log would work, but MathExpressions.log() takes the base as second argument.
The only way that I think this would work, is that, under SQL Server 2008 (or wherever it also may not work) the base is ignored and only LOG10 is used.
Do you know which versions of SQL Server have the LOG(float) function? (so don't have the LOG(float, base) function)
Then we can aggregate all our findings here and resolve it.

@Shredder121

This comment has been minimized.

Show comment
Hide comment
@Shredder121

Shredder121 Oct 6, 2014

Member

I just thought of a better solution (If MSSQL's floating point operation is precise enough)
We can also use the change of base method to emulate the logarithm's base, then we don't have to ignore the base argument.

http://en.wikipedia.org/wiki/List_of_logarithmic_identities#Changing_the_base
(wikipedia link instead)

@timowest Does this sound like a viable solution?

Member

Shredder121 commented Oct 6, 2014

I just thought of a better solution (If MSSQL's floating point operation is precise enough)
We can also use the change of base method to emulate the logarithm's base, then we don't have to ignore the base argument.

http://en.wikipedia.org/wiki/List_of_logarithmic_identities#Changing_the_base
(wikipedia link instead)

@timowest Does this sound like a viable solution?

@janfrodeh

This comment has been minimized.

Show comment
Hide comment
@janfrodeh

janfrodeh Oct 6, 2014

Looks like LOG(float) is natural logarithm up to and including SQL Server 2008, from 2008R2 it is 10-base logarithm. The docs say that if base is omitted, it defaults to 10-base...

Edit: It might be a typo in the docs, because I tried SELECT LOG(10) on both SQL Server 2008 and 2012, and they both returned 2,3025.... If that is the case LOG(float) is natural logarithm on at least 2005 through 2014.

Looks like LOG(float) is natural logarithm up to and including SQL Server 2008, from 2008R2 it is 10-base logarithm. The docs say that if base is omitted, it defaults to 10-base...

Edit: It might be a typo in the docs, because I tried SELECT LOG(10) on both SQL Server 2008 and 2012, and they both returned 2,3025.... If that is the case LOG(float) is natural logarithm on at least 2005 through 2014.

@Shredder121

This comment has been minimized.

Show comment
Hide comment
@Shredder121

Shredder121 Oct 6, 2014

Member

according to http://msdn.microsoft.com/en-us/library/ms190319.aspx#sectionToggle0

By default, LOG() returns the natural logarithm. Starting with SQL Server 2012, you can change the base of the logarithm to another value by using the optional base parameter.

So to me it looks like, before SQL Server 2012, there is only one argument.

Where did you find that if base is omitted it defaults to base 10?

Member

Shredder121 commented Oct 6, 2014

according to http://msdn.microsoft.com/en-us/library/ms190319.aspx#sectionToggle0

By default, LOG() returns the natural logarithm. Starting with SQL Server 2012, you can change the base of the logarithm to another value by using the optional base parameter.

So to me it looks like, before SQL Server 2012, there is only one argument.

Where did you find that if base is omitted it defaults to base 10?

@janfrodeh

This comment has been minimized.

Show comment
Hide comment

On this page: http://msdn.microsoft.com/en-us/library/ee634774(v=sql.110).aspx

But I suspect that it is a typo.

@Shredder121

This comment has been minimized.

Show comment
Hide comment
@Shredder121

Shredder121 Oct 6, 2014

Member

Yes, I can confirm it is a typo, I happen to have SQL Server 2012 installed (also installing 2008 to fix this issue) and running select LOG(100,10), LOG(100), LOG10(100) results in:

2 4,60517018598809 2

So, definitely, the 3 formulas do not return the same result, 2.
But better to be sure of course.

Member

Shredder121 commented Oct 6, 2014

Yes, I can confirm it is a typo, I happen to have SQL Server 2012 installed (also installing 2008 to fix this issue) and running select LOG(100,10), LOG(100), LOG10(100) results in:

2 4,60517018598809 2

So, definitely, the 3 formulas do not return the same result, 2.
But better to be sure of course.

@Shredder121

This comment has been minimized.

Show comment
Hide comment
@Shredder121

Shredder121 Oct 6, 2014

Member

Sorry, forgot to add the 'bug' label.

Member

Shredder121 commented Oct 6, 2014

Sorry, forgot to add the 'bug' label.

@timowest timowest added this to the 3.5.1 milestone Oct 7, 2014

@timowest timowest closed this in #992 Oct 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment