Calculates the logarithm of the factorial with given argument.

You're viewing an older version of this page (#286). View the current version.

View versions (1)

Interface

#include <codecogs/maths/combinatorics/arithmetic/log_factorial.h>

using namespace Maths::Combinatorics::Arithmetic;

This function calculates the following expression

\mathrm{log factorial}(n) = \mathrm{ln}\,n!
(1)

In the given example, values of this function are returned for various integral values of the argument from 1 up to 10.

Example 1

#include <codecogs/maths/arithmetic/log_factorial.h>
#include <iostream>
#include <iomanip>

int main()
{
  std::cout << std::setprecision(10);
  for (int i = 1; i <= 10; i++)
  {
    std::cout << "log_factorial(" << i << ") = ";
    std::cout << Maths::Arithmetic::log_factorial(i);
    std::cout << std::endl;
  }
  return 0;
}

Output

log_factorial(1) = 0
log_factorial(2) = 0.6931471806
log_factorial(3) = 1.791759469
log_factorial(4) = 3.17805383
log_factorial(5) = 4.787491743
log_factorial(6) = 6.579251212
log_factorial(7) = 8.525161361
log_factorial(8) = 10.6046029
log_factorial(9) = 12.80182748
log_factorial(10) = 15.10441257

Parameters

n
the argument of the factorial

Returns

the logarithm of the factorial with given argument n
GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

n
Result