On Sep 29, 2007, at 12:26 PM, Norman Palardy wrote:
>
> On 29-Sep-07, at 12:51 AM, Frank Condello wrote:
>
>> So, for fun, I implemented the approximation in pure RB code. I knew
>> the bit shift would be a problem but I was curious as to how Rb would
>> handle it - here's what I ended up with:
>>
>> Function FastSqrt(x As Single) As Single
>> #pragma BackgroundTasks False
>> #pragma BoundsChecking False
>> #pragma NilObjectChecking False
>> #pragma StackOverflowChecking False
>> Static m As New MemoryBlock(4)
>> Static p As Ptr = m
>> Dim i As Integer
>> Dim y As Single
>> p.Single(0) = x
>> i = p.Integer(0)
>> i = &h5f375a86 - Bitwise.ShiftRight(i,1)
>> p.Integer(0) = i
>> y = p.Single(0)
>> y = y*(1.5-0.5*x*y*y)
>> return x * y
>> End Function
>
> What about getting rid of the bitshift ?
>
> i = &h5f375a86 - (i/2)
I tried this (actually i\2). It saved a few ms, but that's it.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|