Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Everyone,
I'm having a hard time looking up a function for powers but without invoking math.pow.
Our professor wants us to look it up.

If some one could direct me to the right path. I've been googling it, but math.pow always comes up.

Please help

Sincerely

Juan V.

What I have tried:

I've been to the Microsoft website and googling it and no luck. the math.pow is always showing up, and i understand why
Posted
Comments
an0ther1 8-Feb-16 17:59pm    
You need to do more research. Perhaps try adding in different search terms such as "Math.Pow c# alternatives" or researching what Math.Pow does so that you can determine how you could write it as a method yourself

Kind Regards
jvaca1 8-Feb-16 22:10pm    
Thank you very much, this is great advice. At school its really every person for themselves and I do not have anyone to toss around ideas as a group. I hope its not like this later but I hope I could rely on the member of this website to help me become a great programmer.

Sincerely

Juan
Sergey Alexandrovich Kryukov 8-Feb-16 19:01pm    
What's wrong with System.Math? Please don't refer to your professor; you should use your own brain. What a stupid assignment, "to look it up". Are you sure you are in real school, or maybe this is one of the schools just faking education?
—SA
jvaca1 8-Feb-16 22:15pm    
My professor wants us to understand how much effort is needed to run a powers program from scratch, this is the reason my professor asked us not to use System.Math.

Thank you very much for taking time to respond to my question.

Sincerely

Juan
Sergey Alexandrovich Kryukov 8-Feb-16 23:46pm    
Then this is programming from scratch, not "lookup". It's elementary mathematics, not Microsoft site.
Is the power should be integer value or not? a>
What have you tried so far?
I mean, really tried, not what you wrote under "What I have tried".
—SA

1 solution

One approach would be to find out how the pow function may be implemented (search term may be "math pow implementation"). This should give you code examples for special cases (e.g. second argument is integer, Exponentiation by squaring - Wikipedia, the free encyclopedia[^]) or the implementations of math libraries (e.g. within the GNU C standard library). While the results might be hard to understand for a beginner, they should be valid answers for your professor (show the necessary effort).

Another approach is looking for a mathematical analogon for the pow function which should give you
pow(x, y) = exp(log(x) * y)

While this is a good solution from the mathematical point of view, it is problematic when implementing it using a programming language because the result can become inaccurate.
 
Share this answer
 
Comments
George Swan 9-Feb-16 4:30am    
Well done, Jochen, that's exactly what I would have suggested. You are very brave answering a homework question on here. The last time I did that I received a reprimand from the forum police and multiple penalty points. Have a 5 from me and good luck to you.
Jochen Arndt 9-Feb-16 4:48am    
Thank you George.

It is a homework question but Juan showed enough efforts in the comments to deserve some help.

In such cases I (and hopefully most others here) will help. With homework questions it is often difficult to answer without doing the work itself. But I think this is no problem here because I gave only some directions for further investigation which has to be finally summed up by Juan.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900