Curious formula generating all digits of square root numbers

5 stars based on 55 reviews

How do you calculate the square root of a number? Well, now-a-days it's easy--just use sqrt. But suppose you don't have that function, how else can you do it? Here are some various ways of doing it, from Newton's Method to the paper-and-pencil "long square root" method that I was taught in grade school which is akin to long division. SQRT Here's the best way but least fun. It's here for timing purposes: Or just use [:: Newton's Method This is an iterative process that takes an initial guess and successively makes it better using the recursion: The tricky part is knowing when to stop pick some epsilon and determining the initial guess--any value will do, but some converge faster.

A lot has been written as to the best initial guess; the algorithm I use here is to use a number whose high-bit position is half that of the original number.

I learned this method in grade school, but it seems to be a forgotten technique. In assembly language, working in base 2, this is a blazingly fast and very compact algorithm involving just shifts, adds and comparisons. As a refresher and to get a common terminology, in long division, you have the divisor, dividend and quotient. Each step involves bringing down the next digit from the dividend and adding it to the running dividendthen finding the maximum digit Dwhich multiplied by the divisor is less than the running dividend.

That digit D then becomes part of the quotient. In long square root the method is almost identical except that you bring down pairs of digits and the divisor analog is a varying, more complex value. The square root analog to the divisor, dividend and quotient terms I'll call cross termsquareand root.

Each step involves bringing down the next 2 digits from the square and adding it to the running squarethen finding the maximum digit D which multiplied by the cross term see below is less than the running square. That digit D then becomes part recurrence relation for the digits of the integer square root in binary the root. The cross term part changes at each step. AM It is a pity that this method can not easily be extended to arbitrary roots, such as the cubic root.

Note that the method boils down to: Long Square Root -- reals The above method can easily handle real numbers--just like in long division, when you reach the decimal point just keep bringing down 0's but for square root you bring down pairs of 0's. A tricky part is keeping track of where the decimal point should go.

This function will return as many decimal places as its input, to wit, supplying 2. Should use powers of 2 for this! I was reading [ 2 ] Wayback Machine Web Archive about some obscure code that calculates an approximation to the inverse square root of a number i.

What particularly interested me was the method of calculation, which I reproduce here in Tcl code with some simplifications to make the code a bit more readable: Repeating the last calculation step will produce better approximations: There are for example tons of results that the asymptotic complexity of computing some function e.

As for the magical starting approximation which is analysed in a paper [ 3 ] linked to by the text linked to abovethe idea is if recurrence relation for the digits of the integer square root in binary simplifies heavily to multiply the exponent of the floating point number by The trick relies on the fact that the float i is in IEEE format, ii is 32 bits long but changing the magic constant 0x5fdf suffices for adapting the trick to other sizesand iii has the same endianness as the integers. See also [ 4 ].

Supposing that recurrence relation for the digits of the integer square root in binary does not exist? I can't resist offering the following trivial alternative: What if you do not have exp? Getting started What is Tcl? Tcl in the wild Major applications.

Binary option trading a brief introduction

  • Handel mit binare optionen ist verdienen der broker

    Best canadian online trading sites

  • Forex market hours in pakistan dubai

    Tricks fur binare optionen 6020

Wir handeln die binaren

  • Binary options trading online platform

    When do options start trading in the morning

  • Power options binary 60 seconds trading strategy 2015

    Turbo 5 minute binary options fast money with 5 minutecom

  • 10 minute binary options strategies investoocom trading school brokers and offers

    Mvst part 1b options trading

Ramas sbi forex en delhi

13 comments Switzerland binary options trading demo account

Stock market trading hours usa

For more information, speak to a registered financial advisor to learn more about the tax consequences of making an early RRSP withdrawal. But you will pay an immediate tax on the money you take out (called a withholding tax), and possibly more at tax time. Learn more about making RRSP withdrawals before you retire.

Learn how to contact FSCO and information on locked-in accounts.