TizzyT

DecimalSqrt

Feb 19th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.44 KB | None | 0 0
  1.     Public Function DecimalSqrt(ByVal Number As Decimal, _
  2.                                 Optional ByVal guess As Nullable(Of Decimal) = Nothing) As Decimal
  3.         Dim ourGuess As Decimal = guess.GetValueOrDefault(Number / 2D)
  4.         Dim result As Decimal = Number / ourGuess
  5.         Dim average As Decimal = (ourGuess + result) / 2D
  6.         If average = ourGuess Then Return average Else Return DecimalSqrt(Number, average)
  7.     End Function
Advertisement
Add Comment
Please, Sign In to add comment