sqrt() Calculate Square Root
#include <math.h>
double sqrt(x);
double x; Non-negative floating-point value
sqrt() returns the square root of 'x'. 'x' must be a non-negative,
floating-point number.
Returns: Square root of 'x'. If 'x' is negative, matherr() is
called with a DOMAIN error, a DOMAIN error message is
printed to 'stderr', 'errno' (defined in <stdlib.h>) is
set to EDOM (defined in <math.h>), and 0.0 is returned.
Notes: Error handling can be modified by using the matherr()
routine.
-------------------------------- Example ---------------------------------
The following statements calculate the square root of 25.0, 0.0, and
-4.0 (-4.0 causes an error):
#include <math.h> /* for sqrt() and EDOM */
#include <stdio.h> /* for printf() */
#include <stdlib.h> /* for errno */
main()
{
double a, b, c;
a = sqrt(25.0); /* a = 5.0 */
b = sqrt(0.0); /* b = 0.0 */
errno = 0;
c = sqrt(-4.0); /* c = 0.0, causes EDOM error */
if (errno == EDOM)
printf("EDOM error in sqrt()\n");
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster