Updated: 9 August 2010

Use FACTLN to calculate the natural logarithm of a factorial. It can be useful to have the natural logarithm available because the limits of the **float** data type in SQL Server limit the maximum value of a factorial to 171! The natural logarithm can be substituted in many calculations; just remember to use the EXP() function on the final result.

SELECT [wctStatistics].[wct].[FACTLN] (

<@Number, float,>)

is the value to be evaluated by the function. *@Number *is an expression of type **float** or of a type that can be implicitly converted to **float**.

float

· If *@Number *< 0, FACTLN returns an error.

· *@Number* is truncated to zero decimal places.

SELECT wct.FACTLN(5)

This produces the following result

----------------------

4.78749174278205

(1 row(s) affected)

SELECT EXP(wct.FACTLN(200) - wct.FACTLN(175))

This produces the following result

----------------------

7.01372425899837E+56

(1 row(s) affected)