32 bit square root


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    7


    Did you find this post helpful? Yes | No

    Default pbp code for 1% accurate square root

    Charles

    Give this a try

    '----------- Start PicBasicPro Code--------
    'Taylor expansion to compute 1% accurate square roots scaled up by 64
    'Copyright by Dave Saum 2009, no rights reserved
    'Please email me if you find errors or improvements: DSaum at infiltec dot com
    '
    'Variables:
    Sqr64x var word 'output 1% accurate sq root scaled up by 64
    Input var word 'input integer for sq root
    '
    'Calculation:
    Sqr64x=sqr Input 'first approximation to square root, unscaled
    Sqr64x=(Sqr64x<<6)+((((Input-(Sqr64x*Sqr64x))<<5)+(Sqr64x>>1))/Sqr64x) 'more accurate sqr root, scaled up by 64
    '
    'Sample Calculation:
    'If you take the sq root of 5 and scale it up by 64, the answer is (5^0.5)*64=143.108
    'If you use the PBP sqr function for this: sqr(5)*64 = 2*64 = 128 or 10.6% error under 143.108
    'But, using the Sqr64x code above:
    'Sqr64x= (2*64)+((((5-(2*2))*32)+(2/2))/2)
    ' = 128+(((32+1))/2 = 128 +16 = 144 or 0.6% error over 143.108
    '------------- end code ------

    Hope this helps,

    Dave
    http://www.infiltec.com/seismo
    http://www.infiltec.com/Infrasound@home
    http://www.infiltec.com/SID-GRB@home
    http://www.infiltec.com/inf-fun.htm
    Last edited by DSaum; - 22nd March 2009 at 21:05.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Replies: 3
    Last Post: - 18th March 2008, 04:29
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. 32 bit data displaying on LCD
    By selahattin in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 15th September 2006, 13:33
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts