The calculation instantly reaches 256 lines, after which an error appears

External: SIGFPE on line 76

What am I doing wrong?

76. t:=-x*t/6*k; unit Unit1; {$mode objfpc}{$H+} interface uses Math ,Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, crt; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Label1Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button2Click(Sender: TObject); begin close; end; procedure TForm1.FormCreate(Sender: TObject); begin Memo1.Clear; end; procedure TForm1.Label1Click(Sender: TObject); begin end; procedure TForm1.Button1Click(Sender: TObject); var k,c,c2:integer; t,s,x,eps:real; begin Memo1.Clear; clrscr; val(Edit1.Text,x,c); val(Edit2.Text,eps,c2); if c2=0 then begin if c=0 then begin t:=2*x; s:=t; k:=1; Memo1.Lines.Add('k'+' '+'s'+' '+'f'); Memo1.Lines.Add(inttostr(k-1)+' '+FloattostrF(s,fffixed,3,3)+' '+floattostrf(t,fffixed,3,3)); while abs(t)>eps do begin t:=-x*t/6*k; s:=s+t; Memo1.Lines.Add(inttostr(k)+' '+FloattostrF(s,fffixed,3,3)+' '+floattostrf(t,ffexponent,3,3)); k:=k+1; end; end else showmessage('Введите пожалуйста число!') end else showmessage('Введите пожалуйста число!') end; end. 
  • I suspect the division by zero, if you specify which of the lines is the 76th, it will be easier to guess. - Vladimir Martyanov
  • @ Vladimir Martiyanov at the top of 76 line indicated (t: = - x * t / 6 * k;) - Alexander
  • Well, it means k = 0 on this line. Debugger look. - Vladimir Martyanov
  • Code formatting is awful. I advise you to bring in line with the norms of the language. - Kromster

1 answer 1

t grows exponentially. At the next iteration, the result simply does not fit in Real

And you are sure that here

t:=-x*t/6*k;

no error? Maybe it meant

 t:=-x*t/(6*k); 

?