Officially goin out of my mind. Trivial INT problem - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: Officially goin out of my mind. Trivial INT problem (/showthread.php?tid=1020) Pages:
1
2
|
RE: Officially goin out of my mind. Trivial INT problem - SMcNeill - 10-31-2022 (10-31-2022, 05:32 PM)bplus Wrote: .1 decimal = Question solved -- it's *impossible* to represent 0.1 *perfectly* in floating point values! Which goes to also answer your question of: "Why y not 35.5100000000000000?" It's just one of those impossible representations in binary math. As you said, we can't *truly* represent 1/3 in decimal math (at least not without the use of a repeater bar), and we can't represent the value of 35.51 perfectly either. It's an imprecise value and thus gives imprecision errors when used. It's just the nature of floating point values and imprecise fractions. A much better solution is to keep everything as INTEGER values and then divide by 100 only at the display time for the end user. Instead of working with 35.51, work with 3551. Count pennies, not dollars, and you can avoid a vast majority of these problems. RE: Officially goin out of my mind. Trivial INT problem - bplus - 10-31-2022 We can say .1 in Binary is 1/1010 in Binary ie express as ratio of 2 Integers like we do with 1/3 in decimal. |