Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>pow() calculate x raised to the yth power</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 pow()                   Calculate X Raised to the Yth Power

 #include   <math.h>

 double     pow(x,y);
 double     x;                           Number to be raised
 double     y;                           Power of x

    pow() calculates the value of 'x' raised to the power of 'y'.

    Returns:    'x' raised to the power of 'y'.  If 'x' is 0.0 and 'y' is
                negative, matherr() is called with a DOMAIN error, a
                DOMAIN error message is printed to 'stderr', and 'errno'
                (defined in <errno.h>) is set to ERANGE (defined in
                <errno.h>).

    If 'x' is zero or negative, and 'y' is not an integer or is zero,
    matherr() is called with a DOMAIN error, a DOMAIN error message is
    printed to 'stderr', 'errno' is set to EDOM (defined in <math.h>),
    and 0.0 is returned. On overflow, matherr() is called with an
    OVERFLOW error, 'errno' is set to ERANGE, and positive or negative
    HUGE_VAL (defined in <math.h>) is returned.  On underflow 0.0 is
    returned. (matherr() is not called on an underflow and 'errno' is not
    set.)

         Notes:     The value of any 'x' raised to the power of 0.0 is
                    1.0.

                    You can modify error handing with the matherr ()
                    routine.

   -------------------------------- Example ---------------------------------

    The following statements calculate x raised to the power of y for
    several pair of values in an array, then report any errors:

           #include <math.h>     /* for pow(), HUGE_VAL, ERANGE, and EDOM */
           #include <stdio.h>    /* for printf() */
           #include <errno.h>    /* for errno */

           double vals[6][2]={{-3.0, 4.0},   /* 81.0 */
                             {0.0, 0.0},    /*  1.0 */ (EDOM error)
                             {0.0, -1.0},   /*  -1.79e+308 (EDOM error) */
                             {-1.0, 1.1},   /*  -1.79e+308 (EDOM error) */
                             {9.9, 999.9},  /* HUGE_VAL (OVERFLOW: ERANGE)*/
                             {10.0, -444.0}}; /* 0.0 (UNDERFLOW: no error)*/

           main()
           {
               double x_to_the_y;
               int i;

               for (i = 0;  i < 6;  i++) {
                   errno = 0;
                   x_to_the_y = pow(vals[i][0], vals[i][1]);
                   /* on any error except an OVER- or UNDERFLOW, an
                    error message is also printed to stderr */
                   if (errno == EDOM)
                       printf("EDOM error in pow()\n");
                   else if (errno == ERANGE)
                       if (x_to_the_y == HUGE_VAL)
                           printf("OVERFLOW error in pow()\n");
                       else
                           printf("ERANGE error in pow()\n");
                   printf("%f raised to the %f = %e\n",
                          vals[i][0], vals[i][1], x_to_the_y);
               }
           }


See Also: exp() log() log10() sqrt()

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