Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / c++ exp() - how to in AGK?

Author
Message
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 29th May 2013 21:27
I've been looking for a way to duplicate the exp() function of c++.

This is the exponential function of x.

I have looked around and think that Euler's number e can be used as a constant somewhere in the calculation.

Haven't been able to see a breakdown of this function (that I could understand anyway).

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 29th May 2013 23:40
It is just e^x
according to
http://www.cplusplus.com/reference/cmath/exp/

I do wonder how long e is in the c++ function.

nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 30th May 2013 00:03
e, I gather is euler's number - let's say 2.7182818284590452353602874713527 - apparently it's been computed to a trillion places

So, seeing as exp(5.0) is supposed return 148.413159 according to that example, I tried it in AGK.. and ...

I get 79.432350

Same if I use the windows CALC to work it out..

Oh.. hang on - did it back to front - haha.. x^e

Well, AppGameKit returns 148.413132. This is probably down to the precision of the e value, but hey - it works - thanks for the reply.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 30th May 2013 00:04
Quote: "I do wonder how long e is in the c++ function."

It's probably #defined somewhere and so will be used as a double. In AppGameKit we're limited to 32 bit floats.

So a basic exp function would go like this:
#constant E 2.71828

Function exp(x as float)
result# = E^x
Endfunction result#

nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 30th May 2013 00:19
Yep, that all fits together. Wasn't sure what precision we were stuck with in AGK.

I'm sure it will be precise enough though.

Login to post a reply

Server time is: 2024-11-24 13:52:59
Your offset time is: 2024-11-24 13:52:59