Question regarding pow() function
tony at joshua.math.ucla.edu
tony at joshua.math.ucla.edu
Wed Feb 1 11:28:18 AEST 1989
I am having a problem using the pow() function in Micrsoft C and
I was wondering if someone out there can point out what I am doing
wrong.
I'm trying to use the pow () function to raise negative one (-1)
to the power n, i.e. flip the sign back and forth.
What I'm doing is something like:
#include <math.h>
void foo ()
{
int n ;
for (n = 0 ; n < 10 ; n++)
printf ("%lf",pow (-1,n)) ;
}
I am getting a "DOMAIN" error for each pow() call when I do this.
According to my library guide, the pow function is defined as follows:
double pow (x,y)
double x ;
double y ;
...If x is negative and y is not an integer, the function
prints a DOMAIN error message to stderr, sets errono to EDOM,
and returns 0...
My int n variable is being cast into a double, hence this error.
Can someone tell me how I can get around this?
(I know I can use if statements to see if the sign should be - or +
but I'd rather use the pow() function. Its more elegant...)
What is pow (0.,0.)? I am getting a value 0 but shouldn't it be undefined?
More information about the Comp.lang.c
mailing list