Здравствуйте! Пишу программу, делающую простые математические вычисления. На строке проверки условия if где берётся модуль числа Abs программа вылетает и выдаёт ошибку Project Project1.exe raised exception class EnvalidOP with message 'Invalid Floating point operation'
Вот весь код
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, StdCtrls;
type
mas = array of extended;
mas2 = array of integer;
TForm1 = class(TForm)
Button1: TButton;
Chart1: TChart;
Series1: TLineSeries;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
n,tau,eps,i, kol_org,j:integer;
lymb,dt:extended;
x:mas;
mas_org:mas2;
begin
n:=20000;
dt:=1;
lymb:=1.85;
tau:=800;
eps:=10;
kol_org:=0;
setlength(x,n+tau);
for i:=0 to tau-1 do
x[i]:=0.1;
for i:=tau-1 to n+tau-2 do
x[i+1]:=( dt*(-x[i]+lymb-x[i+1-tau]*x[i+1-tau])+eps*x[i] )/eps;
for i:=0 to n+tau-1 do
begin
if ( (x[i]>0) and (x[i+1]<0) ) or ( (x[i]<0) and (x[i+1]>0) ) then
begin
kol_org:=kol_org+1;
end;
end;
setlength(mas_org,kol_org);
j:=0;
for i:=0 to n+tau-1 do
begin
if (((x[i]>0) and (x[i+1]<0)) or ((x[i]<0) and (x[i+1]>0))) then
begin
if (Abs(x[i])<Abs(x[i+1])) or (Abs(x[i])=Abs(x[i+1])) then
mas_org[j]:=i else mas_org[j]:=i+1;
j:=j+1
end;
end;
Series1.Clear;
for i:=0 to n+tau-1 do
Series1.AddXY(i,x[i]);
end;
end.
В чём ошибка? Помогите пожалуйста.
Что интересно, если закомментировать условие где выдаётся ошибка
Код:
if (Abs(x[i])<Abs(x[i+1])) or (Abs(x[i])=Abs(x[i+1])) then
mas_org[j]:=i else mas_org[j]:=i+1;
то программа всё равно выдаёт ошибку, но только на строке