[fpc-pascal] Loss of precision when using math.Max()

Jim Lee jlee54 at gmail.com
Tue Jul 3 01:26:55 CEST 2018



On 07/02/18 15: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
>
>
>

Should the compiler balk at this as well?

program Project1;

var a,b,c: byte;
begin
   a:=5;
   b:=6;
   c:=a-b;
   writeln(c);    // result: 255
end.

Without the implicit conversion of signed/unsigned values, the utility 
of the language is greatly diminished.

-Jim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180702/7d34d129/attachment.html>


More information about the fpc-pascal mailing list