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


|