[fpc-pascal] Loss of precision when using math.Max()
C Western
l at c-m-w.me.uk
Tue Jul 3 09:26:15 CEST 2018
On 02/07/18 23:13, Wolf wrote:
> Not so long ago, Florian was proudly bragging about "Pascal does not
> allow you to shoot yourself in the foot
> <http://www.toodarkpark.org/computers/humor/shoot-self-in-foot.html>"
>
> What about this little program:
>
> program Project1;
>
> var a,b: byte;
> begin
> a:=1;
> b:=a*(-1);
> writeln(b); // result: 255
> end.
>
> The result is obviously correct, given how the variables are declared.
> But there are no compiler warnings / errors that the assignment
> b:=a*(-1) is fishy, to put it mildly. And if you are serious about
> strong typing, it ought to be illegal, with a suitable complaint from
> the compiler.
>
> Who is shooting whom in the foot?
>
> Wolf
>
If you compile with range checks on, you get a runtime error.
Colin
More information about the fpc-pascal
mailing list