computing floating point powers
Author Message
computing floating point powers

i need to evaluate the expression e^(-at) where -at is a float value as well.can anybody

Mon, 24 Apr 2000 03:00:00 GMT
computing floating point powers

Quote:

> i need to evaluate the expression e^(-at) where -at is a float value as well.can anybody

#include <math.h>

double d;

d  = exp(-a*t);

Mon, 24 Apr 2000 03:00:00 GMT
computing floating point powers

Quote:
> i need to evaluate the expression e^(-at) where -at is a float

value as well.can anybody

Quote:

Have you looked at the pow() function in math.h?

Jack

Tue, 25 Apr 2000 03:00:00 GMT
computing floating point powers

Quote:
(DAVID KOIDL) writes:
> i need to evaluate the expression e^(-at) where -at is a float value

Do you mean e as in Euler's number?  Or just a general float value?
For the latter, use pow(), for the former use exp() -- both are
defined in <math.h>:

#include <math.h>

double   foo = pow(0.35, -1.13);
float    bar = powf(2.0, 0.5);

double   baz = exp(2 * 3.1415926535984);
float    frob = expf(7.0);

math libraries when you compile (depending on the system you're
using).

Cheers,
-M

-- . -.. .. .- . ...- .- .-.. .. ... -  -.-. --- -- .--. --- ... . .-.
Michael J. Fromberger
Software Engineer, Thayer School of Engineering
Dartmouth College, Hanover, New Hampshire, USA

--. ..- .. - .- .-. .. ... -  .-.. .. -. --. ..- .. ... -  -- .--- ..-.

"Alway the nye slye maketh the ferre leeve to be looth."

Tue, 25 Apr 2000 03:00:00 GMT
computing floating point powers

Quote:

> #include <math.h>

> double   foo = pow(0.35, -1.13);
> float    bar = powf(2.0, 0.5);

> double   baz = exp(2 * 3.1415926535984);
> float    frob = expf(7.0);

Neither powf() nor expf() are standard C functions.

--
<\___/>      | "Love is a snowmobile racing across the tundra and
/ O O \      | then suddenly it flips over, pinning you underneath.
\_____/ FTB. | At night the ice weasels come..."

Tue, 25 Apr 2000 03:00:00 GMT
computing floating point powers

Quote:

> > i need to evaluate the expression e^(-at) where -at is a float
> value as well.can anybody

> Have you looked at the pow() function in math.h?

I doubt very much if the pow() function is in the header
file...

--
<\___/>      | "Love is a snowmobile racing across the tundra and
/ O O \      | then suddenly it flips over, pinning you underneath.
\_____/ FTB. | At night the ice weasels come..."

Tue, 25 Apr 2000 03:00:00 GMT
computing floating point powers

Quote:

article

> > > i need to evaluate the expression e^(-at) where -at is a
float
> > value as well.can anybody

> > Have you looked at the pow() function in math.h?

> I doubt very much if the pow() function is in the header
> file...

Especially since standard headers are not required to be files...

Wed, 26 Apr 2000 03:00:00 GMT
computing floating point powers

Jack & Colin engaged in a "pedantic contest"

Quote:
>> > Have you looked at the pow() function in math.h?

>> I doubt very much if the pow() function is in the header
>> file...

>Especially since standard headers are not required to be files...

But if we insert one word,
"Have you looked at the pow() function 'prototyped'  in math.h"
Then the statement is entirely correct and it does not matter if math.h is a
file or a magic word to the compiler.

Of course, to perform e^x, I  would use exp(), but that is beside the point.
Also, since he was asking for
e^(-at)
I suspect that what he was REALLY after was:
double val = exp(-a*t);
Where t is time or some independent variable.

I'm at home, so I say anything I please.

Wed, 26 Apr 2000 03:00:00 GMT
computing floating point powers

Quote:
> i need to evaluate the expression e^(-at) where -at is a float value as
well.can anybody

Take a look at the exp function.

(just in case e is a variable, and not the base of natural logarithms, as I
have assumed, take a look at the pow function.)

#include <math.h>

Wed, 26 Apr 2000 03:00:00 GMT

 Page 1 of 1 [ 9 post ]

Relevant Pages