procedure TForm1.Button1Click(Sender: TObject); var y, yInDegree, EPS, diff, x, yMinus1 : Extended; i, n : Cardinal; begin x := StrToFloat(Edit1.Text); n := StrToInt(Edit3.Text); EPS := StrToFloat(Edit2.Text); i := 1; y := 1.0; yInDegree := 1.0; while (diff > EPS) do begin yMinus1 := y; y := ((1/n) * ((n-1) * y + (x/yInDegree))); // <<<-- Ошибка тут yInDegree := exp(n*ln(y)); diff := y - yMinus1; inc(i); end; Label5.Caption := IntToStr(i); end; 

Error text:

Project Project1.exe raised exception class EInvalidOp with message 'Invalid floating point operation'

The error takes off on the line y := ((1/n) * ((n-1) * y + (x/yInDegree))); .

  • and this comment is definitely not nuzhuen - pavel
  • one
    Not compiled or not working? What is the error text? Which line? - Anton Shchyrov
  • the error takes off on the line y: = ((1 / n) * ((n-1) * y + (x / yInDegree))); Error text: Project Project1.exe raised exception class EInvalidOp with message 'Invalid floating point operation' - Nick
  • n (it is Edit3.text) not exactly zero? - Smithson
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Either n , or, more likely, yInDegree at the next iteration takes values ​​around zero.

Modify the code

 try y := ((1/n) * ((n-1) * y + (x/yInDegree))); except ShowMessageFmt('n: %f, y: %f, yInDegree: %d', [n, y, yInDegree]); end; 

and look at the resulting values