SRL Archive - Lape

Casting integer as extended in lape


Gu3st...

2013-12-11 22:18:31

So I can do this:
round(1); even though 1 is an integer and not an extended, and I can do this:
maxE(1, 2); even though 1 and 2 is integers and not extended, but I can't do this:
function minMax(const i, low, high : Extended): Extended;
begin
if i < low then
exit(low);
if i > high then
exit(high);
result := i;
end;

function minMax(const i, low, high : Integer): Integer; overload;
begin
result := round(minMax(i, low, high)); // <----- This line right here
end;

begin
writeLn(minMax(2.0, 0, 1));
writeLn(minMax(2, 0, 1));
end.
If I want that code to run without erroring, I'd have to change line 12 to this instead:
result := round(minMax(i*1.0, low*1.0, high*1.0));

This "bug"/feature/whatever was also present in PascalScript, but I thought Lape didn't have it too.

Anyone have an explanation?

E: I can also copy+paste the contents of the extended resulting version of the minMax function into the integer resulting version to get it to work, but that kind of defeats some of the purpose of "overload"

bonsai

2013-12-12 08:53:15

The problem isn't really casting here, it's that you are calling the integer function from within the integer function. It is recursively calling itself until it runs out of memory.

Put "writeln('hi')" inside the function to see.

Gu3st...

2013-12-12 08:55:23

From: bonsai
The problem isn't really casting here, it's that you are calling the integer function from within the integer function. It is recursively calling itself until it runs out of memory.

Put "writeln('hi')" inside the function to see.
:redface:

Yes. You're right. Nevermind this thread :)