![]() |
Power Functions returning Zero
Hey all,
I think I must be brain damaged, because I am having the dumbest problem. I need a power function for a program, and every single one I use is returning zero at all times. I've tried the math.h pow() and two other functions, one recursive and one non-recursive. The frustrating thing is that this is a tiny, trivial part of what I'm trying to do (find the root of a scalar equation with newton's method), and I can't even seem to get out of the gate. I've tried compiling with g++ and gcc (need g++ for pow() of course), I've tried changing the value of j, swapping j and cx, changing the types of j and cx, and a whole bunch of other junk. Any help would be greatly appreciated. Here's the code, along with the debugging statements that prove to me that I'm getting the wrong answer. ------------------------------------------- Code:
#include<math.h> |
Re: Power Functions returning Zero
The problem is that ya have used the specifier %d for double type......that is not valid.....i suggest try %l or %lf
|
Re: Power Functions returning Zero
Thanks! I'll give that a try when I get off work. Although, I'm confused -- those functions all return a double, so shouldn't I specify a double?
Thanks! |
Re: Power Functions returning Zero
%d is an integer....
|
Re: Power Functions returning Zero
Ah, ok. Thanks DaWei. That might be causing me problems elsewhere too.
|
Re: Power Functions returning Zero
Yeah.... so I used %f and now all the power functions are returning 0.000000.
Any other ideas? Thanks in advance... |
Re: Power Functions returning Zero
Oh wait... my bad... it's working with %lf.
Yay!!! Thanks to you both. |
| All times are GMT +5.5. The time now is 04:44. |