but it's use would be cumbersome
(SNIP!)Code: QB64: [Select]
Steve said it some time ago, I paraphrase: Separate the calculations with variables function from the displaying of the results function.
You just need a good format routine to adjust for garbage that enters into calculations with floats. Probably would include rounding to the precision of decimals you desire in the output (display) format.
For CharlieJV this seems to work:Code: QB64: [Select][ This attachment cannot be displayed inline in 'Print Page' view ]
Next i
Well shoot, seems to be stopping at .9 not 1, dang!
OK this fixes that!Code: QB64: [Select]
Personally, here's the general method I use when I have to deal with this type of thing:Code: QB64: [Select](snip!)
I don't know if I can ever again trust a loop that involves incrementing by decimal values.
Maybe a knee-jerk reaction, but I find myself wondering, looking at any kind of loop like that, if there is unintentional short-changing of the loop (or an opposite "over-loop"?) by an iteration.
(SNIP!)
I still say the absolute best solution, when possible, is to just avoid the floating point imperfections entirely.
FOR i = -10 TO 10 'use integers when possible
iDec = i /10 'only convert to the floating point value when necessary
NEXT
It's why the banks track how many PENNIES are in your account, and not how many dollars. The results are displayed as dollars, but all the calculations are in pennies.
CharlieJV
maybe use while loops instead
@CharlieJV you might be in habit of thinking of i as an incremented (by 1) integer index (like for arrays).
jack is suggesting a While loop I think to try an get that last loop for i when it isn't an incremented (by 1) integer index but I had same idea tried it and still i a single type + .1 collects gabage and passes exactly 1.000 just like in For loop!
@CharlieJV you might be in habit of thinking of i as an incremented (by 1) integer index (like for arrays).
No, I am not thinking that. When I do a For i = 1 to 5, I expect 1,2,3,4,5 to happen.
jack is suggesting a While loop I think to try an get that last loop for i when it isn't an incremented (by 1) integer index but I had same idea tried it and still i a single type + .1 collects gabage and passes exactly 1.000 just like in For loop!Translation While doesn't work either.
gcc runtime library has decimal arithmetic functions https://gcc.gnu.org/onlinedocs/gccint/Decimal-float-library-routines.html so it may be possible to use them in QB64tried it, but unfortunately QB64 passes the arguments by reference and they need to be by value
LOL, I thought April Fools day was yesterday!
(SNIP!)
Hey Steve I was thinking - uh oh, get ready...
...and I know you're infinitely busy already, all thoughts and prayers going your way. That said, can I humbly encourage your QB64 Bible project to hit the issue of floating point math next? Even if it wasn't the next chapter you were going to write, we need something final on this question once and for all. It comes up way too often in the forums. The proper write-up should minimize out-of-house references, and be something written entirely by us, for us - and you're the guy to do it Steve. The challenge is to write it out *so good* that it answers every question that ever came up about floating point math in qb64.exe, and also anticipates every future question that may arise. Do whatever you want to do, but make this section stand perfectly alone, and write it soon. No references to other chapters, just a stand alone gospel on QB64's float.
This might make the overall project feel less daunting. Do chapters by demand. Do float while it's fresh. Invest the 10,000 keystrokes and you'll save us all 100,000. Pretty Virginia Please.
Computers don't usually work in base 10, they work in base 2.