05-04-2025, 04:40 PM
Does QB64 behave like the original QB45 commands in these situations? If so then all is good. If not then it needs fixed to behave as QB45 would.
Extended KotD #25, #26, and #27: INTEGER DIVISION, CINT, and CLNG
|
05-04-2025, 04:40 PM
Does QB64 behave like the original QB45 commands in these situations? If so then all is good. If not then it needs fixed to behave as QB45 would.
05-04-2025, 04:44 PM
From what I can tell we seem to mimic QB45 perfectly. It's just we haven't really documented this behavior and explained it very well for people in the past. The wiki is woefully lacking important details about exactly how people should expect CINT, CLNG, and _ROUND to work.
05-04-2025, 05:05 PM
I think my point got lost in translation
![]()
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
05-04-2025, 05:13 PM
(05-04-2025, 04:44 PM)SMcNeill Wrote: From what I can tell we seem to mimic QB45 perfectly. It's just we haven't really documented this behavior and explained it very well for people in the past. The wiki is woefully lacking important details about exactly how people should expect CINT, CLNG, and _ROUND to work.But you should also say that this is only the case with one decimal place. from 0.55 the behavior is changed . Code: (Select All)
Code: (Select All)
05-04-2025, 06:04 PM
(05-04-2025, 04:44 PM)SMcNeill Wrote: From what I can tell we seem to mimic QB45 perfectly. It's just we haven't really documented this behavior and explained it very well for people in the past. The wiki is woefully lacking important details about exactly how people should expect CINT, CLNG, and _ROUND to work. This is all QB45 help contains on CINT, do we really need more? ![]() I guess we could add this example to it. ![]()
05-04-2025, 06:51 PM
(05-04-2025, 05:13 PM)Steffan-68 Wrote:(05-04-2025, 04:44 PM)SMcNeill Wrote: From what I can tell we seem to mimic QB45 perfectly. It's just we haven't really documented this behavior and explained it very well for people in the past. The wiki is woefully lacking important details about exactly how people should expect CINT, CLNG, and _ROUND to work.But you should also say that this is only the case with one decimal place. That's why I mentioned this: value < 0.5 rounds down. value = 0.5 rounds to the nearest even integer. value > 0.5 rounds up. X.49999999999999 rounds down. x.50000000000001 rounds up.
05-04-2025, 08:47 PM
We have cint and clng (and c__ for lots of types) in VBA & vbscript for casting values.
I realize these are for rounding and may not be the exact equivalent, but they will come in handy. Thanks for sharing. Now, what is KotD?
05-04-2025, 09:25 PM
(05-04-2025, 08:47 PM)madscijr Wrote: We have cint and clng (and c__ for lots of types) in VBA & vbscript for casting values. Keyword of the Day. The whole series of posts that are in this subforum. ![]()
05-04-2025, 10:38 PM
(This post was last modified: 05-04-2025, 10:41 PM by PhilOfPerth.)
@SMcNeill:
This stream has already achieved one major goal: to raise awareness of the unexpected results we may get when using Integers Your final short snippet sums up everything (at least, for me)! value < 0.5 rounds down. value = 0.5 rounds to the nearest even integer. value > 0.5 rounds up. X.49999999999999 rounds down. x.50000000000001 rounds up. If that's what happens in every case - pos or neg - then the world is sweet!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.)
![]() Please visit my Website at: http://oldendayskids.blogspot.com/
05-04-2025, 11:29 PM
(05-04-2025, 10:38 PM)PhilOfPerth Wrote: @SMcNeill: Note that this is what we see in CINT, CLNG, _ROUND. Other commands don't have this same behavior. Any single, double, or float assigned to an integer obeys these same rules of rounding, as you can see from the below. (Pay close attention to the .5 entries and see how one rounds up and the other rounds down, as they're both rounding to the closest even integer. Code: (Select All)
Also note that other rounding type commands don't obey this pattern or rule, such as INT (always rounds down), CEIL (always rounds up), FIX (truncates). What I'm mentioning here is for CINT, CLNG, _ROUND, and direct assignment of floating point values to integer types. |
« Next Oldest | Next Newest »
|