function Sidi_method(equation, x0 = 0, x1 = 1, y, options) {
var error = Number.EPSILON;
if (!options) options = {};
else if (options > 0) error = options;
else if (options.error > 0) error = Math.abs(options.error);
y = +y || 0;
var count = (options.count || 40) | 0,
y0 = 'y0' in options ? options.y0 : equation(x0),
y1 = 'y1' in options ? options.y1 : equation(x1);
if (
typeof options.start_OK === 'function' &&
!options.start_OK(y0, y1)
)
return;
var x2 = x1 - ((x1 - x0) * (y1 - y)) / (y1 - y0),
y2 = equation(x2),
x3 = x2,
y3 = y2,
y10 = (y1 - y0) / (x1 - x0),
y21 = (y2 - y1) / (x2 - x1),
y210 = (y21 - y10) / (x2 - x0),
denominator;
while (
error < Math.abs(y3 - y) &&
count-- > 0 &&
y21 !== 0 &&
(denominator = y21 + y210 * (x2 - x1)) &&
((x3 = x2 - (y2 - y) / denominator) !== x2 || x2 !== x1 || x1 !== x0)
) {
y3 = equation(x3);
(x0 = x1), (y0 = y1);
(x1 = x2), (y1 = y2);
(x2 = x3), (y2 = y3);
y10 = y21;
y21 = (y2 - y1) / (x2 - x1);
if ((y210 = y21 - y10)) y210 /= x2 - x0;
}
return { x: x3, count: 40 - count, fm: y3 - y };
}