D notation bug - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +---- Forum: GitHub Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=42) +---- Thread: D notation bug (/showthread.php?tid=1834) Pages:
1
2
|
D notation bug - bplus - 07-09-2023 As reported at the other forum: Code: (Select All) Print (1D+17) * (1D+17) ' <<< the buggy one! The D notation is off by 1 power of 10. RE: D notation bug - Jack - 07-09-2023 I remember Pete and I made some posts about it in the .org forum besides the case you present, there were a number of anomalies, what does your example produce? I get 9.999999999999999D+33 ' which is correct as far as floating-point goes, it's off by 1.0E-16 1E+34 note that I get this from my version, I modified the double-to-string and _float-to-string routines RE: D notation bug - Jack - 07-09-2023 bplus, see what you get from the following Code: (Select All)
RE: D notation bug - mnrvovrfc - 07-09-2023 Try this in QBasic. If the output is the same then it stays fellas. RE: D notation bug - DSMan195276 - 07-09-2023 (07-09-2023, 05:00 PM)bplus Wrote: As reported at the other forum:I'm pretty sure it's just a problem with rounding along with how the number is displayed. The floating point error for the double results in the value being slightly less than 1D+34, and because the value is slightly less it gets rounded to 1D+33 when displaying. While I don't know what QBasic used to do. this seems like a bug since the number is still significantly closer to 1D+34 than 1D+33, so it should be displayed as that. I suspect it may be just rounding the mantissa without adjusting the exponent or something, I took a quick look at the code that renders the number but the issue wasn't clear to me. The way it works is pretty weird as it is, it might be easier to just redo it. RE: D notation bug - SMcNeill - 07-09-2023 Code: (Select All)
Run the above and watch what happens. No matter whether you like single (E) or double (E) values, they're all still floating point numbers and as such are *always* going to behave imperfectly due to the way the values get stored and processed in binary memory. 1E13 * 1E13 = 9.9999999E25..... whereas 1D13 * 1D13 = 1D26. <-- In this case, the 1D26 gives us the proper answer, while the 9.9999E25 is imprecise. 1D17 * 1D17 should probably give us 9.999999D33, as that's as close as it comes to calculating that value perfectly, but for whatever reason, the left is rounding to 1 (it's not truncating, as the answer then would be 9E33) and the right isn't incrementing to 34 as it ought to. These values will never come out as perfectly precise as folks would like them to, but this does seem to be an issue with rounding screwing up somewhere in the "D" code. RE: D notation bug - bplus - 07-09-2023 Quote:1D17 * 1D17 should probably give us 9.999999D33 Right! that's about it with rounding errors, not almost 10 X's less that I am seeing. How does E do it with no rounding problems and correct exponent? @matt I tried the mantissa idea with 15 significant digits on the guy at the other forum and he didn't buy it, it's a bug and I think he's right because E works just fine. @mnrvovrfc It does work correctly in older QB according to the guy at other forum. @jack yeah I am sure your code is likely correct! ;-)) RE: D notation bug - Jack - 07-09-2023 @bplus in the code I posted above, the doubles are converted to string using the snprintf function, please replace Print strf(c#) with Print c# and see what the output looks like RE: D notation bug - bplus - 07-10-2023 (07-09-2023, 10:40 PM)Jack Wrote: @bplus @Jack I am missing the point you are trying to make? BTW Print (1D+17) * (1D+17) ' <<< the buggy one! is coming out wrong at 1D+33 in case you didn't try it. RE: D notation bug - Jack - 07-10-2023 bplus, the point was to show any buggy output by QB64 native double to string conversion as in your example Print (1D+17) * (1D+17) as you can see in your output you have two 1D+22 and no 1D+23, also you have two 1D+28 and no 1D+29 using the C snprintf function would show them correctly |