Calculate the square root.
#include <math.h>
double sqrt( double x );
long double _sqrtl( long double x );
x | Nonnegative floating-point value |
The sqrt functions calculate the square root of x. The _sqrtl function is the 80-bit counterpart and uses an 80-bit, 10-byte coprocessor form of arguments and return values.
The sqrt functions return the square-root result. If x is negative, the function prints a _DOMAIN error message to stderr, sets errno to EDOM, and returns 0.
Error handling can be modified by using the _matherr or _matherrl routine.
sqrt
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
_sqrtl
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
/* SQRT.C: This program calculates a square root. */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
double question = 45.35, answer;
answer = sqrt( question );
if( errno == EDOM )
printf( "Domain error\n" );
else
printf( "The square root of %.2f is %.2f\n", question, answer );
}
The square root of 45.35 is 6.73