realbasic-nug
[Top] [All Lists]

Re: High Performance Code (Was: Bitwise Shift operators)

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: High Performance Code (Was: Bitwise Shift operators)
From: Norman Palardy <npalardy at great-white-software dot com>
Date: Sat, 29 Sep 2007 10:26:22 -0600
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <BAY107-DAV8132ACB18FF1E0678E2E693B20 at phx dot gbl> <981FFB08-71D3-487B-8A80-4352EE252BB4 at chaoticbox dot com>
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)

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>