<div dir="ltr"><div>An issue recently popped up that I thought I'd bring up as a potential issue. In short, if you call the Max() function with an integer and a double parameter (such as d := Max( 0, d ) ), then fpc appears to be using the Max( single, single ) overloaded function instead of Max( double, double ). This is causing a loss of precision once the double values get large enough. Here is a sample program which illustrates the issue:</div><div><br></div><div><font face="monospace">program project1;<br><br>uses<br>  Math<br>  , SysUtils<br>  ;<br><br>var<br>  d : Double;<br>  s : Single;<br><br>begin<br>  d := 159279.49;<br>  writeln( '159279.49 stored in Double d = ' + FloatToStr( d ) );<br>  d := Max( 0, d );<br>  writeln( 'Max( 0, d ) stored in Double d = ' + FloatToStr( d ) );<br>  writeln();</font></div><div><font face="monospace"><br>  s := 159279.49;<br>  writeln( '159279.49 stored in Single s = ' + FloatToStr( s ) );<br>  s := Max( 0, s );<br>  writeln( 'Max( 0, s ) stored in Single s = ' + FloatToStr( s ) );<br>  writeln();<br><br></font></div><div><font face="monospace">  d := s;<br>  writeln( 'Assigning the value of s to Double d = ' + FloatToStr( d ) );<br>end.</font><br></div><div><br></div><div>Doing a bit of research on this issue, I see that it was brought up on Stack Overflow back in 2018 <a href="https://stackoverflow.com/questions/52020129/unexpected-result-from-max-function-in-freepascal">here</a>. We can work around the issue by sending in 0 as 0.0, which then calls the correct Max( double, double ) function.</div><div><br></div><div>Cheers,</div><div>  Alan</div><div><br></div><div><br></div><div><br></div><div><br></div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br><table border="0" cellspacing="0" cellpadding="0" style="width:592px;font-family:"Times New Roman";font-size:medium"><tbody></tbody></table></div></div></div></div></div></div></div></div></div></div></div>