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

Santiago A. svaa at ciberpiula.net
Tue Jul 3 14:01:15 CEST 2018


El 03/07/2018 a las 01:26, Jim Lee escribió:
>
>
>
> 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.

Let's be honest, compared to C and many other languages (included C++, 
that is a suicide without extra-language analyzer tools), Pascal is very 
type secure. For instance, many languages allow assigning a float to an 
integer without any problem. Moreover without being clearly specified by 
language definition what the compiler should do, truncate or round.

Pascal needs to break backward compatibility to advance, that is, in 
fact, a new language. But if pascal is struggling to survive, let alone 
a new language if you are not mozilla, google...

>
> -Jim
>
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


-- 
Saludos

Santiago A.

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


More information about the fpc-pascal mailing list