标签:
import UIKit func babylonianMethod (toSqrt number: Double, epsilon: Double) -> Double{ // epsilon 是精度控制 var Xn0: Double = 1 var Xn1: Double = (Xn0 + number / Xn0) / 2 while( fabs(Xn0 - Xn1) > epsilon) { Xn0 = Xn1 Xn1 = (Xn0 + number / Xn0) / 2 } return Xn1 } babylonianMethod(toSqrt: 2, 1e-10)
标签:
原文地址:http://www.cnblogs.com/baaingSheep/p/4696329.html