logl Function

Calculates the natural logarithm of a single precision floating-point value.

Include

<math.h>

Prototype

long double logl(long double x);

Argument

x
any positive value for which to return the log

Return Value

Returns the natural logarithm of x. -inf is returned if x is 0 and NaN is returned if x is a negative number.

Remarks

A domain error occurs if x ≤ 0.

Example Output

#include <math.h>
#include <stdio.h>
#include <errno.h>

int main(void)
{
  long double x, y;

  errno = 0;
  x = 2.0F;
  y = logl(x);
  if (errno)
    perror("Error");
  printf("The natural logarithm of %Lf is %Lf\n",
          x, y);

  errno = 0;
  x = 0.0F;
  y = logl(x);
  if (errno)
    perror("Error");
  printf("The natural logarithm of %Lf is %Lf\n",
          x, y);

  errno = 0;
  x = -2.0F;
  y = logl(x);
  if (errno)
    perror("Error");
  printf("The natural logarithm of %Lf is %Lf\n",
          x, y);
}

Example Output

The natural logarithm of 2.000000 is 0.693147
The natural logarithm of 0.000000 is -inf
Error: domain error
The natural logarithm of -2.000000 is nan