I'm working on a program that I need to use this equation:
1/2^n where n is a for loop number going up to 8. what can i use instead of carrot (^) to square or exponetiate somthing?
Plz help,
Artanis
I'm working on a program that I need to use this equation:
1/2^n where n is a for loop number going up to 8. what can i use instead of carrot (^) to square or exponetiate somthing?
Plz help,
Artanis
std::pow(double, double);
from <cmath>
i.e.
double result = std::pow(.5, n);
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
thanks, how could i have been so stupid, heh heh
well, you could also create you're own recursive function, but that isn't necessary... but i feel like it and i'm bored, so...
there it is... although it only works for positive exponents...Code:#include <iostream> using namespace std; double power(double,double); int main() { double number; double exp; ... cout<<"Answer: "<<power(number,exp); return 0; } double power(double number, double exp) { if(exp>1) return number*power(number, exp-1); else return number; }
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
in your power function you need to add...
Code:else if(exp==0) return 1;
that's why i said positive ;-)
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
oops i didnt see that sorry
Although writing your own functions is the best exercise, and there's nothing more fun than creating a recursive function The built-in library functions are almost always better (bug-free, fool-proof, flexable, etc.)
And, a "simple" recursive function can't do this: pow(0.5, 2.4)... In fact, I don't know how to do that! Hmmm, I'd have to dig out my math books... must have something to do with summing exponents...
Raise 0.5 to the 24th power, and take the 10th root (or the 12th power and take the 5th root, etc.). Use your home-built recursive function for the raising, but alas the only way I ever figured out how to get roots (other than the square root) is std::pow...Originally posted by DougDbug
And, a "simple" recursive function can't do this: pow(0.5, 2.4)... In fact, I don't know how to do that! Hmmm, I'd have to dig out my math books... must have something to do with summing exponents...
well recursive functions are fun to write... kinda like linked lists... or am i just strange?
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
I wonder how difficult it would be to make our own exp function with inline assembly...Arn't their ASM commands to do logarithms? (I don't have any x86 reference manuals, otherwise I would look in those)
"What are you after - the vague post of the week award?" - Salem
IPv6 Ready.
Travel the world, meet interesting people...kill them.
Trying to fix or change something, only guaruntees and perpetuates its existence.
I don't know about angels, but it is fear that gives men wings.
The problem with wanting something is the fear of losing it, or never having it. The thought makes you weak.
E-Mail Xei
Wow, you all went so far off from my question... Though these inquires are intriguing. I say thanks to Zach L. I didn't have time to make a recursive function, though it almost came to that!