Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: Fast FEXP a...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 9 Topic 3971 of 4136
Post > Topic >>

Re: Fast FEXP approximation

by Albert van der Horst <albert@[EMAIL PROTECTED] > Mar 25, 2008 at 09:52 PM

In article
<52dbca89-dfec-4a70-85d6-fe70f60bd640@[EMAIL PROTECTED]
>,
Ian Osgood  <iano@[EMAIL PROTECTED]
> wrote:
>On Mar 25, 11:10=A0am, Andrew Haley <andre...@[EMAIL PROTECTED]
>
>wrote:
>> Ian Osgood <i...@[EMAIL PROTECTED]
> wrote:
>> > I recently ran across a fast approximation for exp() which relies on
>> > the internal structure of IEEE doubles, implemented as a cast integer
>> > multiply by a magic constant. Is this already known to the Forth
>> > community?
>>
>> Surely it's just a polynomial approximation to exp(x), with order 1
>> and 0.5 <=3D x < 1; it can't be that, though, because it would be
>> nowhere near accurate enough. =A0
>>
>> I an see why a right ****ft of an IEEE double with a little diddling of
>> the low-order bits would be roughly there. =A0How rough an
approximation
>> is this? =A0:-)
>>
>> Tang's algorithm is fast, but there's a bit more to it than just a
>> multiply. =A0Can't be that.
>>
>> OK, go on, tell us...
>>
>> Andrew.
>
>fvariable ftemp
>: fexp-fast ( f -- e^f )
>  700e fover fabs f< if fexp exit then
>  [   $100000. d>f 2e fln f/ ] fliteral f*
>  [ $3ff00000 68243 - 0 d>f ]  fliteral f+
>  f>d ( swap) ftemp 2! ftemp f@[EMAIL PROTECTED]
 ;
>
>The swap is needed on big-endian machines (PPC). 68243 represents the
>minimum mean error.
>
>This was a hack to optimize some neural-network code. This is
>reputedly 10x faster than typical exp() library routines in the given
>range [-700..700].

That gives it away. For neural network code 3 bits precision is
plenty ;-)

Seriously, on the Pentium exp translates to one assembler
instruction, and it is guaranteed to be less than one bit
off, mostly less than half a bit off.
That is hard to beat, even sacrificing precision.

>
>Ref: http://citeseer.ist.psu.edu/14416.html

>
>Ian


--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@[EMAIL PROTECTED]
 &=n http://home.hccnet.nl/a.w.m.van.der.horst
 




 9 Posts in Topic:
Fast FEXP approximation
Ian Osgood <iano@[EMAI  2008-03-25 07:45:30 
Re: Fast FEXP approximation
Andrew Haley <andrew29  2008-03-25 18:10:46 
Re: Fast FEXP approximation
Ian Osgood <iano@[EMAI  2008-03-25 11:25:31 
Re: Fast FEXP approximation
mhx@[EMAIL PROTECTED] (M  2008-03-25 21:08:24 
Re: Fast FEXP approximation
Albert van der Horst <  2008-03-25 21:52:18 
Re: Fast FEXP approximation
Frank <fjrusso@[EMAIL   2008-03-27 16:23:43 
Re: Fast FEXP approximation
Albert van der Horst <  2008-03-28 08:53:31 
Re: Fast FEXP approximation
anton@[EMAIL PROTECTED]   2008-03-28 20:42:20 
Re: Fast FEXP approximation
Albert van der Horst <  2008-03-29 17:08:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 6:08:07 CDT 2008.