Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
April 29th, 2003, 03:46 PM
 jack37a
Junior Member

Join Date: Apr 2003
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
fast exponential function algorithm

Hi !

I am trying to write a program which calculates an exponential function as fast as possible on a PC
I tried a polynom approximation. It is the fastest algorithm i have
got and it has an accurracy of 10 digits.
take a look!

---------------------------------------------------------------------

const float umrechnungf=0.434294481903251f;

const float z00=1.00000000000000f;
const float z11=1.258925411794167f;
const float z22=1.584893192461113f;
const float z33=1.995262314968879f;
const float z44=2.511886431509580f;
const float z55=3.162277660168379f;
const float z66=3.981071705534972f;
const float z77=5.011872336272723f;
const float z88=6.309573444801932f;
const float z99=7.943282347242815f;
const float Kette24Lf=10.423067565678043f;
const float Kette12Lf=5.211533782839021f;
const float Kette50LLf=9.430584850580696f;
const float Kette10LLf=1.886116970116139f;

float Jacks_Exp(float Wert)

{

W=fabs(Wert*umrechnungf);

g=int(W);
z=int((W-g)*10);
h=W-(float(g)+float(z)/10);

switch (z)
{
case 0 : binaer=z00;break;
case 1 : binaer=z11;break;
case 2 : binaer=z22;break;
case 3 : binaer=z33;break;
case 4 : binaer=z44;break;
case 5 : binaer=z55;break;
case 6 : binaer=z66;break;
case 7 : binaer=z77;break;
case 8 : binaer=z88;break;
case 9 : binaer=z99;break;
}

ergebnis = pow(10,g)*binaer*((Kette24Lf/(Kette12Lf-h-(Kette50LLf/(Kette10LLf/h+h))))-1);

if (Wert < 0)
return (1/ergebnis);
else
{
return ergebnis;
}

}

I know that floats are very slow - especially divisions.
I would be very thankfuf if some could help me. Maybe some has a solution to my problem or some hints how I could improve the performance of my algorithm.
Is there a faster way of dividing floating numbers ?
Does anybody know a better algorithm ?
Could someone also recommend me some good books which deal with this kind of the problem.

Jack

#2
April 30th, 2003, 10:02 AM
 mathew
Registered User

Join Date: Feb 2003
Location: Slovak republic
Posts: 15
Time spent in forums: 1 h 27 m 4 sec
Reputation Power: 0
"unlimited" accuracy

hi.

the fastest way to work with numbers is to use some optimized library. I should sugest you GMP lib. (www.swox.com/gmp).
It could be used to work with huge numbers (even millions digits each number or more) and also with huge accuracy (limited only by your memory).
It has all mathematical functions (mul, div, pow, log, binary operations, and much more....) and it is one of the fastest (if not the fastest one) functions cose it is speed optimized.

i hope i helped you.

 Viewing: Dev Shed Forums > Programming Languages - More > Software Design > fast exponential function algorithm