Variable stuck on 24 bits - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Variable stuck on 24 bits (/showthread.php?tid=2037) Pages:
1
2
|
Variable stuck on 24 bits - DimColby - 09-25-2023 Hello all. I have a problem that has been plaguing me in my QB64 adventure. If I have a variable, and I increment it, by just the number 1 in a loop, when it gets to 1.677722E+07 (24 bits) it just stops and increments no more. Doesn't matter if I use LONG or _INTEGER64 data types, or don't declare a type at all. Sounds like it has to be a bug, and a weird one. Why 24 bits? Anyone else see this? RE: Variable stuck on 24 bits - mnrvovrfc - 09-26-2023 Welcome to the forums. You are expecting help but do not post source code. So we have to guess what you are trying to do. Are you using `PRING USING` to output the variable's value? This is one of the biggest offenders. If you are incrementing by one, make sure it is `1` as integer, and it's not floating point. Because QB64 sometimes needs the programmer's help by type-casting like must be done regularly in C/C++. Otherwise 24 bits should easily fit into a `LONG` (32-bit) variable. RE: Variable stuck on 24 bits - bplus - 09-26-2023 Yeah I am not seeing it: Code: (Select All) Dim i As _Integer64 Welcome, may I ask what version QB64 you are using? RE: Variable stuck on 24 bits - SMcNeill - 09-26-2023 1.677722E+07 is floating point, and you're at max single digit precision. 16777220 <-- this is what the value above translates to. 16777221 <-- add one 1.677722E+07 <-- and the above still rounds to the same value. You're doing floating point math, not integer addition. RE: Variable stuck on 24 bits - SMcNeill - 09-26-2023 If you're dimming your variable as long or integer64, be certain it's SHARED if you use it in SUB/FUNCTIONs, or else specify the type in your parameters. SUB foo (var AS LONG) RE: Variable stuck on 24 bits - DimColby - 09-26-2023 (09-26-2023, 12:25 AM)SMcNeill Wrote: 1.677722E+07 is floating point, and you're at max single digit precision.Thank you, I think that fixed it. It turns out that declaring it with a DIM didn't really do it, but not declaring it and using the & suffix did. Those two things must not be exactly the same. RE: Variable stuck on 24 bits - DimColby - 09-26-2023 (09-26-2023, 12:11 AM)bplus Wrote: Yeah I am not seeing it:Current one, just downloaded from the Github. RE: Variable stuck on 24 bits - SMcNeill - 09-26-2023 (09-26-2023, 12:58 AM)DimColby Wrote:(09-26-2023, 12:25 AM)SMcNeill Wrote: 1.677722E+07 is floating point, and you're at max single digit precision.Thank you, I think that fixed it. It turns out that declaring it with a DIM didn't really do it, but not declaring it and using the & suffix did. Can you share some code with the glitch? & suffix is the same as DIM AS LONG. I imagine you're seeing an issue with your variable's scope. RE: Variable stuck on 24 bits - SMcNeill - 09-26-2023 Code: (Select All)
Works as advertised for me with the above. RE: Variable stuck on 24 bits - DimColby - 09-26-2023 (09-26-2023, 02:16 AM)SMcNeill Wrote:I see what I did. I was misusing the DIM...AS... statement with a variable list. It's something I remember from way back, using that with lists of variables can give unexpected results and it's safer and no more difficult to declare variables one at a time. Thanks again!(09-26-2023, 12:58 AM)DimColby Wrote:(09-26-2023, 12:25 AM)SMcNeill Wrote: 1.677722E+07 is floating point, and you're at max single digit precision.Thank you, I think that fixed it. It turns out that declaring it with a DIM didn't really do it, but not declaring it and using the & suffix did. |