Re: Implementation of exp()
- Posted by CChris <christian.cuvier at ?gricultur?.gouv.fr> Aug 29, 2007
- 584 views
Al Getz wrote: > > CChris wrote: > > > > Al Getz wrote: > > > > > > Hi there, > > > > > > > > > If you dont like the results of power(e,x) then the only alternative > > > is to implement your own power series. Taylors is the most popular > > > and easy to implement, so maybe start there and check the accuracy > > > of that and compare with power(e,x). > > > Most of the time when i use exp(x) i implement as power(e,x) unless > > > i need better accuracy then i go to a big number routine, but > > > either way i end up using x negative because that comes up so much > > > more in time domain studies of electrical networks and even networks > > > that represent other physical processes. > > > > > > Example: > > > y=a*exp(-t/b) > > > where t is time and a,b are constants depending on circuit values > > > and b is almost always positive. > > > > > > > > > Al > > > > > > E boa sorte com sua programacao Euphoria! > > > > > > > > > My bumper sticker: "I brake for LED's" > > > > > > > No need for such efforts, the standard C library has done it way before us. > > It has a native exp() function, which I checked against arbitrary precision > > computation: the native exp() doesn't have issues, only power(E,x) has. And > > i is not because the value of E is inexact - things are ok as long as x is > > no > > greater than 7 or something. > > > > The implementation would duplicate the code for sin(), with a check for > > overflow > > (the maximum allowable value for x is 1024*ln(2), which is about 694). > > > > CChris > > > > CChris > > > You mean only the Euphoria version of power(e,x) doesnt work > right? > > > Al > > E boa sorte com sua programacao Euphoria! > > > My bumper sticker: "I brake for LED's" > Yes. This has nothing to do with the precision of the E constant - everything is correct as long as x is below 7 or 8, I'd have to check my test file precisely. So E is correctly for a 64-bit double number. I bet the C exp() function is implemented in a way that circumvent this limitation, probably using powers of 2 rather than powers of an irrational atom, then converting back. The FPU instruction set (for Inte processors at lest), has a builtin FYL2X (power(y,ln_2(x)) instruction, which is probably used. I don't know for sure. What I know is that the results are not exactly what they should be as computed with arbitrary precision. CChris