Re: [Ql-Users] Behaviour of DIV with negative numbers in SBASIC (QPC2)

2017-01-06 Thread pjwitte
Tobias, I just tested this against my own version of DIV/MOD and got these results: 100 CLS 110 DivMod 5, 2 120 DivMod -5, 2 130 DivMod -5, -2 140 DivMod 5, -2 150 : 160 DEFine PROCedure DivMod(a, b) 170 PRINT 'd'! a DIV b, 'm'! a MOD b, '='! a * (b DIV a) + b MOD a 180 PRINT 'D'! LDIV(a, b),

Re: [Ql-Users] Behaviour of DIV with negative numbers in SBASIC (QPC2)

2017-01-06 Thread Tobias Fröschle
Yep. Same is true for the Turbo compiler. Tobias > Am 06.01.2017 um 17:07 schrieb Bob Spelten : > > Op Thu, 05 Jan 2017 16:49:09 +0100 schreef Tobias Fröschle > >: > >> Martyn, >> >> Integer division for

Re: [Ql-Users] Behaviour of DIV with negative numbers in SBASIC (QPC2)

2017-01-06 Thread Bob Spelten
Op Thu, 05 Jan 2017 16:49:09 +0100 schreef Tobias Fröschle : Martyn, Integer division for negative numbers is not very well defined. Language designers get to choose if their language will round towards zero, negative infinity, or positive infinity when

Re: [Ql-Users] Behaviour of DIV with negative numbers in SBASIC (QPC2)

2017-01-06 Thread pjwitte
Tobias, I just tested this against my own version of DIV/MOD and got these results: 100 CLS 110 DivMod 5, 2 120 DivMod -5, 2 130 DivMod -5, -2 140 DivMod 5, -2 150 : 160 DEFine PROCedure DivMod(a, b) 170 PRINT 'd'! a DIV b, 'm'! a MOD b, '='! a * (b DIV a) + b MOD a 180 PRINT 'D'! LDIV(a, b),

Re: [Ql-Users] Behaviour of DIV with negative numbers in SBASIC (QPC2)

2017-01-06 Thread Tobias Fröschle
The "flooring" i.e. round down approach is normally chosen to make sure that x = a *(x DIV a) + x MOD a stays valid for negative numbers. That would not necessarily be the case if rounding towards 0. Tobias > Am 05.01.2017 um 16:55 schrieb Martyn Hill : > >

Re: [Ql-Users] Bevaiour of DIV with negative numbers in SBASIC (QPC2)

2017-01-06 Thread George Gwilt
> On 5 Jan 2017, at 15:27, Martyn Hill 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