Square Roots: Babylonian Style!!

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Postby rolliebollocks » Aug 29, 2010 21:04

Yeah I guess you're right... Anyway... it's still cool. Once every two years I remember this thread existed and go back... :)

Code: Select all

' Square Roots!
' by Kristopher Windsor

Function squareroot (Byval number As Double ) As Double
  Dim As Double r1=1, r2=Any

    r2 = r1
    r1 = (r1 + number / r1) * .5
  Loop Until Abs(r1 - r2) <  .001
  Return r1
End Function

Dim As Double t,a

for i as integer = 1 to 10000:a = Sqr(666666669911):next
? timer-t
for i as integer = 1 to 10000:a = Squareroot(666666669911):next
? timer-t

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 3 guests