Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 09-15-2004
BillBoeBaggins
Couldn't you just write a short recursive function to handle "power of" math calls.

Code:

```long PowerOf(long Base_Number, long Power_Of) {     long tmp=0;     static long counter;     while(Power_Of<=counter)     {         counter++;         tmp=Base_Number*(counter);         Power_Of--;         tmp=PowerOf(tmp,Power_Of);;     };                return tmp; }```
(I know this code has flaws)
• 09-15-2004
Hunter2
>>I needed it for a think called HEK
:rolleyes: Another .NET sellout. Did you know I couldn't even install my HP printer drivers on my older computer because it didn't have .NET installed? :mad:

**EDIT**
>>Couldn't you just write a short recursive function to handle "power of" math calls.
a) Why rewrite the standard math library?
b) How would you compute fractional powers by this method?
• 09-15-2004
BillBoeBaggins
Couldn't you just do a bit of code modification and change out the "long" parameters for "float"?

Also, if you aren't interested in the bloat of including more headers files this should help. Or for the novelty, of I don't know, writing something yourself...

I wasn't suggesting it was the be all/end all. Just an alternative. An idea.
• 09-15-2004
Rune Hunter
Quote:

long PowerOf(long Base_Number, long Power_Of)
{
long tmp=0;
static long counter;
while(Power_Of<=counter)
{
counter++;
tmp=Base_Number*(counter);
Power_Of--;
tmp=PowerOf(tmp,Power_Of);;
};
return tmp;
}

don't know what that would do...
• 09-15-2004
Hunter2
>>Couldn't you just do a bit of code modification and change out the "long" parameters for "float"?
No. Because the power-ing is done by whole numbers. An interesting idea though, to do it with recursion... I would have just stuck it in a for loop ;)
• 09-15-2004
moi
using recursion in the place of a simple for loop is not interesting, its slow and clumsy.
• 09-16-2004
BillBoeBaggins
You know I didn't even think of putting it in a loop... :D
• 09-16-2004
The Brain
Recursive power function:

if 'base' is zero, then 'exp' must be positive
Code:

``` double power( double base, int exp)  {       if (base == 0)  //base is zero, and exp should be positive           return 0;       else if (exp == 0)           return 1;       else if (n > 0)                  return base * power(base, exp - 1);       else  //base is nonzero, and exp is negative           return  1/power(base, -exp); }```
• 09-16-2004
Rune Hunter
so can you explain what this does and how to use it if it will help me please?
• 09-16-2004
Hunter2
>>so can you explain what this does and how to use it if it will help me please?
It is a recursive function: It calls itself with changing parameters in order to accomplish the task. And it isn't useful to you at all, since <cmath> includes a pow() function ;)
• 09-16-2004
Rune Hunter
oh lol yes I have already used the pow function for my calculator.
• 09-17-2004
The Brain
Quote:

Originally Posted by Hunter2
>>so can you explain what this does and how to use it if it will help me please?
It is a recursive function: It calls itself with changing parameters in order to accomplish the task. And it isn't useful to you at all, since <cmath> includes a pow() function ;)

sometimes i get joy out of bludgeoning a fly with a hammer ;)
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12