Re: roots
- From: Phil Carmody <thefatphil_demunged@xxxxxxxxxxx>
- Date: Fri, 26 Jun 2009 08:47:49 +0300
pete <pfiland@xxxxxxxxxxxxxx> writes:
user923005 wrote:
On Jun 24, 9:34 pm, "Bill Cunningham" <nos...@xxxxxxxxxxxxx> wrote:
I have written a program that calculates powers or exponentiation but I
would like to write something that would give any root of any number. I know
this would involve factorials. Anyone have any hints? I don't want to use
the math.h header.
If you include math.h then you can use something like this:
#include <math.h>
double root(double base, double root)
{
return pow(base, 1.0 / root);
}
And you can write a power function without math.h;
but I needed about a year of calculus
before I could understand the Taylor series
that I used when I wrote one.
Fortunately CORDIC's pretty trivial for log and exp, so no need
for Taylor/MacLaurin series, or any in-depth knowledge of calculus.
All you need to know is that exp(a+b)=exp(a)*exp(b) and log(a*b)=
log(a)+log(b).
Phil
--
Marijuana is indeed a dangerous drug.
It causes governments to wage war against their own people.
-- Dave Seaman (sci.math, 19 Mar 2009)
.
- Prev by Date: Re: roots
- Next by Date: Re: Graphic GUI C
- Previous by thread: Re: roots
- Next by thread: Re: roots
- Index(es):
Relevant Pages
|