Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>sqrt() calculate square root</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
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");
         }

See Also: exp() log() matherr() pow()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson