I have an integer variable, in S*BASIC, and I'm dividing by another integer variable, with the result being assigned to a third integer variable. The idea is to take a value which is one of the two relative values returned by RPTR (in the S*BASIC toolkit), divide it by a given line depth to get the line number that the pointer was clicked at. Given a row depth of 12 pixels I'm seeing that row 0 is from pixels 0 to 5, row 1 is from pixels 6 to 18 and so on. The first row is bonkers!
Here's the minimal test code that shows the problem:
Code: Select all
1000 define procedure test(a%)
1010 local b%, c%
1020 b% = 10
1030 c% = a% / b%: print "a% / b% = "; c%,
1040 c% = INT(a% / b%): print "INT(...) = "; c%
1050 end define test
Code: Select all
for x = 0 to 10: y% = x: print y%;' = ': test(y%): end for x
Code: Select all
0 = a% / b% = 0 int(...) = 0
1 = a% / b% = 0 int(...) = 0
2 = a% / b% = 0 int(...) = 0
3 = a% / b% = 0 int(...) = 0
4 = a% / b% = 0 int(...) = 0
5 = a% / b% = 1 int(...) = 0
6 = a% / b% = 1 int(...) = 0
7 = a% / b% = 1 int(...) = 0
8 = a% / b% = 1 int(...) = 0
9 = a% / b% = 1 int(...) = 0
10 = a% / b% = 1 int(...) = 1
11 = a% / b% = 1 int(...) = 1
12 = a% / b% = 1 int(...) = 1
13 = a% / b% = 1 int(...) = 1
14 = a% / b% = 1 int(...) = 1
15 = a% / b% = 2 int(...) = 1
16 = a% / b% = 2 int(...) = 1
17 = a% / b% = 2 int(...) = 1
18 = a% / b% = 2 int(...) = 1
19 = a% / b% = 2 int(...) = 1
20 = a% / b% = 2 int(...) = 2
When a% = 5 and b% = 10 for example, then a% / b% gives a result of 0.5 but when that gets assigned to c% it takes the value 1. It looks like it could be rounding the floating point value up to make an INT?
It's caused m,e no end of trouble today, I can tell you!
Any advice, corrections, explanations etc gratefully received. Feel free to hurl insults as well, if necessary!

Cheers,
Norm.