Function RTBIS(X1, X2, XACC:real):real;
Label 99;
var
DX,FMID,F,XMID,RTB:real; J,JMAX:integer;
begin
JMAX:=40;
FMID:=FUN(X2);
F:=FUN(X1);
If F * FMID >= 0 Then
ShowMessage('Root must be bracketed for bisection.');
If F < 0 Then
begin
RTB:=X1;
DX:=X2 - X1;
end
Else
begin
RTB:=X2;
DX:=X1 - X2;
end;
For J:=1 To JMAX do
begin
DX:=DX * 0.5;
XMID:=RTB + DX;
FMID:=FUN(XMID);
If FMID If (Abs(DX) < XACC) Or (FMID = 0) Then goto 99;
End;
ShowMessage('too many bisections');
99: RTBIS:=RTB;
end;