package com.daojia.math;
公共类sque retest {
publicstaticvoidmain{
//todo自动生成方法stub
long t1=system.current time millis (;
doubleSRT=math.sqrt(10000000.0;
双井du=0.001;
long T2=system.current time millis (;
double SRT1=sq1 (10000000.0,0.001 );
long T3=system.current time millis (;
double SRT2=sq2 (10000000.0,0.001 );
longt4=system.current time millis (;
double SRT3=sq3 (10000000.0,0.001 );
() ) ) ) )。
//*
publicstaticdoublesq1(double num,double jingdu ) {
是if (数字0 )
{
() ) ) ) )。
double step=jingdu/5;
double res=0.000;
while(RES*RES
{
res=res step;
() ) ) ) )。
返回结果;
() ) ) ) )。
/*
publicstaticdoublesq2(double num,double jingdu ) {
是if (数字0 )
{
() ) ) ) )。
双最后=0.0000;
双低=0;
双精度mid;
doubleup=(num=1)? num:1;
mid=(lowup )/2;
do{
if(mid*midnum )。
{
up=mid;
}else{
low=mid;
() ) ) ) )。
last=mid;
mid=(uplow )/2;
}while(math.ABS ) mid-last (jingdu );
返回mid;
() ) ) ) )。
/*
publicstaticdoublesq3(double num,double jingdu ) {
是if (数字0 )
{
() ) ) ) )。
double x=num,y=0.0;
while(math.ABS(x-y ) 0.00001 ) {
y=x;
x=0.5*(xnum/x );
() ) ) ) )。
返回x;
() ) ) ) )。
() ) ) ) )。
jdkuse:0:10000.0
2.0E-4
true
二lsdfkuse :033609999.999747378752
true
可以看出,true现在也是计算机很快,对1亿要求精度为0.001的情况。 花了147毫秒。