Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bbn!oberon!sm.unisys.com!ucla-cs!math.ucla.edu!tony From: tony@joshua.math.ucla.edu Newsgroups: comp.lang.c Subject: Question regarding pow() function Message-ID: <400@sunset.MATH.UCLA.EDU> Date: 1 Feb 89 01:28:18 GMT Sender: news@MATH.UCLA.EDU Reply-To: tony@MATH.UCLA.EDU () Distribution: na Organization: UCLA Mathematics Department Lines: 38 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 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?