Date: Wed, 15 Oct 1997 18:03:02 -0700 (PDT) Message-Id: <199710160103.SAA04693@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: br5an AT aol DOT com (Br5an), djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: ' ^ ' Precedence: bulk At 04:36 10/15/1997 GMT, Br5an wrote: >Mike wrote: > >>Hi. I'm just a casual programmer, so excuse me if this is a foolish >>question. I cannot get the ^ operator to work in my programs using DJGPP. It >>returns error messages basically saying it doesn't know what it is. I'll try >>something like this: > >> cout << 3^2; > >>and it happens. Do I have to include some weird header file, or am I just >>screwed? Any help appreciated. > > Mike, > In "C" ^ is the binary operator XOR. As it appears on the > surface I would think your code should work. But obviously it isn't working > for you. I might suggest that you try cout << (3^2); and see if that helps. > On the chance that you wanted 3 raised to the 2nd power, you'd want to look at > the function call pow(3, 2); >#include pow(...) really expects two doubles to be passed to it and > returns a double, but I think this should work. Sorry for posting without > testing anything. Perhaps someone will be along and clarify the situation. Yes, you are right about all that. pow() does indeed do exponentiation. But it does take floating-point numbers (double) for args and return. If you want to work on integers you may have loss of precision when using this floating-point function. For integers you can do something like: int int_pow(int x, int y) { int i; int t = x; for (i=1; i < y; i++) t *= x; return t; } HTH Nate Eldredge eldredge AT ap DOT net