public static double getRoot(Function f, double from, double to, double precision) { // если значения функции на концах отрезка не разных знаков if (Math.Sign(f.getValue(from)) * Math.Sign(f.getValue(to)) > 0) throw new Exception("Values of func have not same char"); double middle = (from + to) / 2; while (Math.Abs(f.getValue(middle)) > precision) { if (Math.Sign(f.getValue(from)) * Math.Sign(f.getValue(middle)) < 0) { to = middle; } if (Math.Sign(f.getValue(middle)) * Math.Sign(f.getValue(to)) < 0) { from = middle; } middle = (from + to) / 2; } return middle; }