<p style="padding:0 0 0 0; margin:0 0 0 0;">Hi,</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">I agree with the original topic that overload function Math.Max(Double, Double) shoud be chosen instead of Math.Max(Single, Single) when one of parameters is Integer.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">But your criticism make no sense to me. You can as well point that this code:</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">var a, b: Byte;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">begin</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> a:=5;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> b:=a div 2;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> writeln(b); <span style="font-size: 13.3333px;">// result: 2</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">end;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">will not give any warning even if correct result is 2.5.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">It is simply absurd because it is not about shooting your own foot. Compiler is not a crystal ball, it does what you tell him.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">If you need floating point, use floating point types and floating point division (my example) and if you need signed results, use signed types (your example).</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">Vojtěch</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: 10pt;">______________________________________________________________</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">> Od: Wolf <wv99999@gmail.com><br />
> Komu: fpc-pascal@lists.freepascal.org<br />
> Datum: 03.07.2018 14:33<br />
> Předmět: Re: [fpc-pascal] Loss of precision when using math.Max()<br />
></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: 10pt;">On 03/07/2018 11:26, Jim Lee wrote:</span></p>
<blockquote cite="mid:88a472c9-d729-7ec9-8362-6b78a145986d@gmail.com">
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<br />
<div class="moz-cite-prefix">On 07/02/18 15:13, Wolf wrote:</div>
<blockquote cite="mid:7209b3ba-27e6-958f-b2be-a62c9e0d7771@gmail.com">
<p style="padding:0 0 0 0; margin:0 0 0 0;">Not so long ago, Florian was proudly bragging about "Pascal does not allow you to <a href="http://www.toodarkpark.org/computers/humor/shoot-self-in-foot.html">shoot yourself in the foot</a>"</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">What about this little program:</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">program Project1;<br />
<br />
var a,b: byte;<br />
begin<br />
a:=1;<br />
b:=a*(-1);<br />
writeln(b); // result: 255<br />
end.<br />
</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">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.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">Who is shooting whom in the foot?</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">Wolf</p>
<br />
</blockquote>
<br />
Should the compiler balk at this as well?<br />
<br />
program Project1;<br />
<br />
var a,b,c: byte;<br />
begin<br />
a:=5;<br />
b:=6;<br />
c:=a-b;<br />
writeln(c); // result: 255<br />
end.<br />
<br />
Without the implicit conversion of signed/unsigned values, the utility of the language is greatly diminished.<br />
<br />
-Jim<br />
<br />
<br />
<fieldset class="mimeAttachmentHeader"></fieldset><br />
<pre>_______________________________________________
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a></pre>
</blockquote>
<br />
<br />
<br />
----------<br />
<br />
_______________________________________________<br />
fpc-pascal maillist - fpc-pascal@lists.freepascal.org<br />
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>