> On 5 Jan 2017, at 15:27, Martyn Hill <martyn.joseph.h...@gmail.com> wrote: > > Hi everyone > > Can anyone tell me the expected behaviour for the integer-divide operator > 'DIV' in SBASIC, when provided with a negative dividend/numerator? > > My number-theory is a bit rusty, but I would have thought that, say, -1 DIV > 10 should result in 0 (with remainder/MOD of -1). > > Instead, on QPC2/SBASIC, I get the result -1 for that example - and (almost) > always 1 less than expected for negative dividends, thus: > > 12 DIV 10 = 1 > 11 DIV 10 = 1 > 10 DIV 10 = 1 > 9 DIV 10 = 0 > ... > 2 DIV 10 = 0 > 1 DIV 10 = 0 > 0 DIV 10 = 0 > * -1 DIV 10 = -1 - expected '0'** > ** -2 DIV 10 = -1** > **...** > ** -9 DIV 10 = -1* > *-10 DIV 10 = -1 - as expected* > *-11 DIV 10 = -2 - expected '-1' > -12 DIV 10 = -2 > > *etc... > > Thanks in advance! > > Martyn.
n DIV m = INT(n/m) INT(a) gives the “integer part” of a. There are three possibilities. 1. a is rounded up 2. a is rounded down 3. a is rounded to nearest In S*BASIC a is rounded down. Thus -11 DIV 10 = INT(-11/10) = -2 George _______________________________________________ QL-Users Mailing List