sqrt


sqrt

Calculates the square root of a floating-point number

 #include <math.h> double sqrt ( double x  ); float sqrtf ( float x  );         (C99) long double sqrtl ( long double x  );         (C99) 

The sqrt( ) functions return the square root of the argument x. If the argument is less than zero, a domain error occurs.

Example

 double x[ ] = { 0.5, 0.0, -0.0, -0.5 }; for ( int i = 0; i < ( sizeof(x) / sizeof(double) ); i++) {   printf("The square root of %.2F equals %.4F\n", x[i], sqrt( x[i] ) );   if ( errno )     perror( _  _FILE_  _ ); } 

This code produces the following output:

 The square root of 0.50 equals 0.7071 The square root of 0.00 equals 0.0000 The square root of -0.00 equals -0.0000 The square root of -0.50 equals NAN sqrt.c: Numerical argument out of domain 

sqrt( ) is also used in the examples shown at erf( ), feholdexcept( ), frexp( ) and signbit( ) in this chapter.

See Also

The complex arithmetic function csqrt( ); the cube root function cbrt( ) and the hypotenuse function, hypot( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net