public class MathSqrtTestDemo
{
public static void main(String[] args)
{
for (double x = 50.0;x <60.0; x++)
{
double y = Math.sqrt(x);
double z = sqrt(x);
System.out.println(y+"\t"+y*y);
System.out.println(z);
}
}
public static double sqrt(double x)
{
final double EPSILON = 1e-14;
if (x <= 0)
return 0;
double y = 1.0;
while (Math.abs(y*y-x) > EPSILON )
y = (y + x/y)/2;
return y;
}
}
Math.sqrt()方法的测试
最新推荐文章于 2024-06-06 14:22:37 发布