|
Post by troycheek on Aug 21, 2015 22:48:34 GMT 1
Somebody please check the following code for me...
Dim a, b, c, d, e As Large a = _maxLarge b = _maxInt c = a / b d = a Div b e = a Div8 b Print a Print b Print c Print d Print e When I try to run the program, I get errors in the lines where d and e are assigned. If I assign values to a and b that are _maxInt or smaller, the program runs, but e is always zero (Div8 doesn't seem to work at all). Is there a bug here, or am I just not understanding how these commands work? I was under the impression that /, Div, and Div8 worked pretty much identically, except that Div was optimized for and returned a Int32 value, and Div8 was optimized for and returned a Int64 value.
|
|
|
Post by dragonjim on Aug 22, 2015 7:12:38 GMT 1
Interesting...
d = a Div b ... this will return an error as Div used as an operator (as in the example) or a function (as in d = Div(a, b)) can only handle integer values up to _maxInt.
However, it would appear that Div8 is simply a copy of Div and 'bugs out' when values exceed _maxInt; however, as Div8 doesn't check for overflow, it returns 0 rather than an error message. This is a bug.
The only version of Div that appears to work with Int64 variables is the command Div a, b which returns the result to a.
I'll update the help file...
|
|
|
Post by troycheek on Aug 22, 2015 20:42:59 GMT 1
I didn't honestly expect the Div operator to work, but I included it with the other tests just to see what would happen. I only recently started to work with Large/Int64 values. Int32 has always been enough for me in the past. I was surprised that the Mod operator didn't work as expected with Large values, did a little research and found the Mod8 and related commands, then surprised again when Div8 didn't work as expected. I also think it's funny that Mod8 and related commands use 8 when they're referring to Int64 variables. I know that 8 bytes and 64 bits are the same thing; you'd just think they'd refer to them in a consistent manner.
|
|
|
Post by dragonjim on Aug 23, 2015 21:08:11 GMT 1
I understand your point about Div8 rather than Div64; I can only assume that, as GB32 is designed to take up as little space as possible (in the days when MBs were expensive and GBs were pipe-dreams), being one character shorter was deemed to be an advantage. Why the functions of Div weren't expanded to handle Int64 numbers is another matter altogether...
|
|
|
Post by dragonjim on Sept 17, 2015 22:21:05 GMT 1
Double checking this before belatedly updating the help file and I noticed the problem lies within the code and not with Div8 which works as described.
The error in the code is the first line which should read: Global Large a, b, c, d, e or the long way round: Dim a As Large, b As Large, c As Large, d As Large, e As Large
The way this line was written in the code set e as a Large variable, but a, b, c and d as Variants (of Double type) which is why there is a Floating Point error.
The following code works as it should (with a Div b returning 0 instead of an error):
Dim a As Large, b As Large, c As Large, d As Large, e As Large a = _maxLarge b = _maxInt c = a / b d = a Div b e = a Div8 b Print a // 9223372036854775807 Print b // 2147483647 Print c // 4294967298 Print d // 0 Print e // 4294967298
|
|