我写的二分法,求方程的解,求大神优化和解释自己的疑问

class fun{
    // TODO Auto-generated method stub
    public static void Bisektion()
    {
    float ymiddle = (float)0.0;
    float yleft = (float)0.0;
    float yright = (float)0.0;

    float a = 0;
    float b = (float)3;


    for(int i = 0;i <=10000;i++)
    {

    float c = (float)((a+b)/2);

    float x = c;
     ymiddle =(float) Math.pow(x, 3)-3*x-3;    // 带入C, C 居于方程的中间
     yleft =(float) Math.pow(a, 3)-3*a-3; 
     yright =(float) Math.pow(b, 3)-3*b-3; 

     if (ymiddle*yleft>0) {
         a = c;
         if(i==10000)
         {
             System.out.println("Die Resultat:"+c);
         }
     }else {
         b = c;
         if(i==10000)
         {
             System.out.println("Die Resultat:"+c);
         }
     }
    }


    }
}
public class Bisektionsverfahren {

    public static void main(String[] args) {
    fun.Bisektion();
    }

}

上面是我写的程序,但是有一个东西完全没有思路,就是如何设置这个循环,尽可能达到double或者float值的极限呢?也就是能达到的最精确的值。

因为实际值在left和right的差之间,所以误差肯定小于left-right的绝对值。
你现在是迭代i <=10000 次
可以改为
while (Math.Abs(yleft - yright) > 0.00001) //精度为0.00001
{
....
}
而不限制迭代次数