yulian
yulian

Reputation: 1627

Error 207 occurs without a reason (invalid floating point operation.)

When I run my program, an error occurs:

program lab_1_27;
uses crt;
var
x, y, z: real;
a: integer;


function pow_udf(m, n:real) : real;
var
  result: real;
begin
  result:= exp(y * ln(x));
end;


begin
  clrscr;

  readln(x);
  readln(y);
  z:= pow_udf(x, y);

  a:= round(z); (* a cursor is in this line after terminating the program *)
  writeln(a);

readkey;
end.

Error:

Error 207: invalid floating point operation.

Please, tell me what is the reason of such behavior because I can't fund it...

Upvotes: 1

Views: 3571

Answers (2)

Matt
Matt

Reputation: 11

Old question, but I was having this same error in a program and my solution was different; might help others searching this error code.

For my program I had used compiler directive N-, and by switching it to N+ I saw a considerable speed increase, but then error 207 started popping up.

Either add directive N- at the top of your source, eg.

{$N-}
PROGRAM ExampleProg;
USES Crt, Dos;

or go into compiler options and disable 8087/80287 processing. This may solve your issue.

Note: if you have compiler directive N+ defined in your source, then changing the options in the IDE won't do a thing; the source code overrules!

Upvotes: 1

Sertac Akyuz
Sertac Akyuz

Reputation: 54802

function pow_udf(m, n:real) : real;
var
  result: real;
begin
  result:= exp(y * ln(x));
end;

The above code assigns the calculation to a local variable named result but fails to return any result from the function. Also it's working on global variables x and y, not on the variables that's passed to the function. Replace it with:

function pow_udf(m, n:real) : real;
begin
  pow_udf:= exp(n * ln(m));
end;

Upvotes: 1

Related Questions