Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

sqrt, sqrtf, sqrtl - Square root

&pagelevel(4)&pagelevel

Definition   

#include <math.h>

double sqrt(double x);
float sqrtf(float x); (C11)
long double sqrtl(long double x); (C11)

These functions calculate the square root of a non-negative floating-point number x.

Return val.

sqrt(x)

if x is >= 0.


0

if x is negative. In addition, errno is set to EDOM (domain error, i.e. invalid argument).

Example

The following program calculates the square root of an input value x.

#include <math.h>
#include <stdio.h>
int main(void)
{
   double x;
   scanf("%lf", &x);
   printf("Square root of %g : %g\n", x, sqrt(x));
   printf("%d\n", errno);
   return 0;
}

See also

exp, pow, log, log10, hypot, sinh