sqrtl Function

Calculates the square root of a double precision floating-point value.

Include

<math.h>

Prototype

long double sqrtf(long double x);

Argument

x
a non-negative floating-point value

Return Value

Returns the non-negative square root of x.

Remarks

If x is negative, a domain error occurs.

Example

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

int main(void)
{
  double x;

  errno = 0;
  x = sqrtl(0.0F);
  if (errno)
    perror("Error");
  printf("The square root of 0.0F is %Lf\n", x);

  errno = 0;
  x = sqrtl(9.5F);
  if (errno)
    perror("Error");
  printf("The square root of 9.5F is %Lf\n", x);

  errno = 0;
  x = sqrtl(-25.0F);
  if (errno)
    perror("Error");
  printf("The square root of -25F is %Lf\n", x);
}

Example Output

The square root of 0.0F is 0.000000
The square root of 9.5F is 3.082207
Error: domain error
The square root of -25F is nan