Borland C++ reference

sqrt, sqrtl

raw OCR

Calculates the positive square root.

Defined in header <math.h>

Syntax

Real versions:                    Complex  version:
#include <math.h>                 #include <complex.h>
double sqrt(double x);            complex  sqrt(complex x);
long double sqrtldong double  x);

Portability

DOSUNIXWindowsANSI CC++ only
sqrtI ■■
Real sqrt ■■■■
Complex sqrt ■■■

Remarks

sqrt calculates the positive square root of the argument x. sqrtI is the long double version; it takes a long double argument and returns a long double result.

Error handling for these functions can be modified through the functions matherr and _matherrl.

For complex numbers x, sqrt (x) gives the complex root whose arg is arg (x)/2.

The complex square root is defined by

sqrt(z) = sqrt(abs(z)) (cos(arg(z)/2) + f sin(arg(z)/2))

Return value

On success, sqrt and sqrtI return the value calculated, the square root of x. If X is real and positive, the result is positive. If x is real and negative, the global variable errno is set to

EDOM Domain error

See also

Example

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

int main(void)
{
   double X = 4.0, result;
   result = sqrt(x);
   printfC'The square root of %lf is %lf\n", x, result);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `sqrt, sqrti` read as `sqrt, sqrtl`