php 开根号 不使用sqrt函数

<?php
/**
 *  $t 是误差范围值
 */
function squre($number ,$t){
    $x1 = $number;
    $x2 = $number/2;
    while( abs($x1 - $x2) > $t){
        $x1 = $x2;
        $x2 = ($x1 + $number/$x1)/2;
    }
    return $x2;
}

echo squre(5,0.1);    

基本思路是使用二分法

原文地址:https://www.cnblogs.com/ryanzheng/p/15065788.html