<!--[if (gte mso 9)|(IE)]><style type="text/css">.main-style-d5965f38e4e06f897670 { font-family: sans-serif; font-size: 11pt; /* inherit */ }</style><![endif]--><div style="/* inherit */" class="main-style-d5965f38e4e06f897670"><div>Hi, <br /></div><div><br /></div><div>my test with Borland Pascal 7.0 running in dosemu2 running 80x87 code. <br /></div><div>The compiler throws an error message for calculating HH and II with explicit type conversion. <br /></div><div>The results of FF and GG are the same!</div><div>Even on 16 bit system!</div><div><br /></div><div>I think this behavior is right!</div><div><br /></div><div>In the 80x87 emulation mode data type single is not available and throws also an error during compilation. <br /></div><div><br /></div><div><span style="font-family: Lucida Console, Monaco, monospace;">PROGRAM Consta;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">Const</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">A_const : integer = 8427;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">B_const : byte = 33;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">C_const : Single = 1440.0;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">Var</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">A_Var : Integer;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">B_Var : Byte;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">C_Var : Single;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">FF, GG, HH, II : Extended;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">begin</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">A_Var := A_Const;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">B_Var := B_Const;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">C_Var := C_Const;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">FF := A_Var+B_Var/C_Var;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">GG := A_Const+B_Const/C_Const;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">(* HH := Extended(A_Const <span style="background-color: rgb(255, 0, 0);"><b><<ERROR ")" expected !! ||</b></span> + B_Const / C_Const); *)</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">(* II := Extended(A_Const <span style="background-color: rgb(255, 0, 0);"><b><<ERROR ")" expected !! ||</b></span> + Extended(B_Const/C_Const)); *)</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">(* HH := Extended(A_Const) <span style="background-color: rgb(255, 0, 184);"><b><< ERROR Type conversion not possible !! ||</b></span> + B_Const / C_Const; *)</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">(* II := Extended(A_Const) <span style="background-color: rgb(255, 0, 184);"><b><< ERROR Type conversion not possible !! ||</b></span>+ Extended(B_Const/C_Const)); *)</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">HH := A_Const + B_Const / C_Const;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">II := A_Const + B_Const / C_Const;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">WRITELN ( ' FF = ',FF: 20 : 20 ) ;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">WRITELN ( ' GG = ',GG: 20 : 20 ) ;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">WRITELN ( ' HH = ',HH: 20 : 20 ) ;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">WRITELN ( ' II = ',II: 20 : 20 ) ;</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;">readln;</span></div><div>end.</div><div><br /></div><div><br /></div><div>----</div><div>Result: <br /></div><div>------</div><div><br /></div><div><span style="font-family: Lucida Console, Monaco, monospace;">Borland Pascal  Version 7.0  Copyright (c) 1983,92 Borland International</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"> FF = 8427.022916666666670000</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"> GG = 8427.022916666666670000</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"> HH = 8427.022916666666670000</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"> II = 8427.022916666666670000</span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"> </span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div><div><span style="font-family: Helvetica Neue, Segoe UI, Helvetica, Arial, sans-serif;">Markus</span><span style="font-family: Lucida Console, Monaco, monospace;"><br /></span></div></div><img src="https://app.frontapp.com/api/1/noauth/companies/schleibinger_geraete_gmbh/seen/msg_jwomzgi/han_9pzu6a/f3b5be1e.gif" alt="Sent from Front" aria-hidden="true" style="width: 1px; height: 1px"><br><blockquote type="cite" class="front-blockquote">On February 6, 2024 at 7:13 PM GMT+1 <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noopener noreferrer">fpc-pascal@lists.freepascal.org</a> wrote:<br /><br /><div id="fae_jwomzgi-tqvc03">>Jonas has argued, not without reason, that calculating everything always at<br />full precision has its disadvantages too.<br /><br />I agree with that, and I do see the value in reducing the precision when it<br />is possible, but not when it's causing data loss. <br />The intention is perfectly fine, it's the execution that has a bug in it. <br /><br />I think that any reasonable person reading the following code would conclude<br />that FF, GG, HH, and II should be exactly the same.  I am defining<br />constants, in FF I define variables of the same type to the constants, and<br />it comes out correctly, in GG I use the constants directly, and its wrong.<br />There is nothing about this that any programmer should understand because<br />it's a bug. <br /><br />FF and GG are both adding an integer to a byte divided by a single, there is<br />no difference to any reasonable programmer between what FF and GG are<br />saying, and the programmer should not have to resort to ridiculous<br />typecasting as in II to get almost the correct answer, but is still wrong.<br />By the way notice that even with the casting, it's still wrong. <br />II SHOULD have produced the right answer, because it's perfectly legitimate<br />to divide a byte by a single and expect the answer to be an extended. <br /><br />program Constant_Bug;<br /><br />Const<br />   A_const = Integer(8427);<br />   B_const = Byte(33);<br />   C_const = Single(1440.0);<br /><br />Var<br />   A_Var : Integer;<br />   B_Var : Byte;<br />   C_Var : Single;<br />   FF, GG, HH, II : Extended;<br /><br />begin<br />   A_Var := A_Const;<br />   B_Var := B_Const;<br />   C_Var := C_Const;<br /><br />   FF := A_Var+B_Var/C_Var;<br />   GG := A_Const+B_Const/C_Const;<br />   HH := Extended(A_Const+B_Const/C_Const);<br />   II := Extended(A_Const+Extended(B_Const/C_Const));<br /><br />   WRITELN ( '     FF = ',FF: 20 : 20 ) ;<br />   WRITELN ( '     GG = ',GG: 20 : 20 ) ;<br />   WRITELN ( '     HH = ',HH: 20 : 20 ) ;<br />   WRITELN ( '     II = ',II: 20 : 20 ) ;<br />end.<br /><br />     FF = 8427.02291666666666625000<br />     GG = 8427.02246093750000000000<br />     HH = 8427.02246093750000000000<br />     II = 8427.02291666716337204000<br /><br />FF and II are correct, GG and HH are wrong.   I understand now WHY this is<br />happening, but I argue, that it's not obvious to anyone that it should be<br />happening, it's just a hidden known bug waiting to bite you.  No reasonable<br />programmer would think that FF and GG would come out differently,  the<br />datatypes are all defined legitimately, and the same, the results should<br />also be the same.<br /><br />In my opinion the changes in v2.2 break more things than they fix, and<br />should be reverted, and used ONLY if asked for by a compiler directive, we<br />should not have to do special things to get it to work correctly.  If you<br />give the compiler directive to use this feature, then you know you might<br />have to cast some things yourself, but to apply this globally and then<br />require a directive to not do it, is just not right, unless ALL code can be<br />run the way it did pre 2.2 without modification,  this is CLEARLY not the<br />case.   <br /><br />James<br /><br />_______________________________________________<br />fpc-pascal maillist  -  <a rel="noopener noreferrer" href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br /><a rel="noopener noreferrer" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br /></div></blockquote><img src="https://u8034135.ct.sendgrid.net/wf/open?upn=liJK2x9lrhmoNbCyBS0MpxjIPwWmvAfUM4RgDSjskX7nFcRXYX2fLyQoEx3O9ue95UqCxFIA9QZrrCKGcQQC2kBTdrWioJPlJmwrNkQhl2GGaOk8T5Rox8pMbkXXxQTYwMOFOwG6Nwc-2FqGstqwEqVu-2FkjQ7crJJID7Kg9M6VrsHMdp8q-2BbQ6rSm-2BBAQNBoHNtb-2BB0iFz99GZj6TzTDdW5DBn-2BXS6UCL5TPRFiuo26TYm-2Fw3gjY2FmV-2FIRLREU79zqci1ohOnO8G5Bdyjoq0ooeIw9AvMhBk9U7OXwu-2B6FgFVK9LjVQFkfRD6GALhavhvsblmgImQD11NWt4UrSPtx3aPaReVijXdAseiIa31Ce4dRI0wjQhIj-2BSSQYLagPIoc8hKNdixMg7bwha035ye-2F4G-2BNvSTak99Er1YNghG9NHn8gHrSBaBJD-2Ba1B9lN1aE" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>