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),
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
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
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),
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 :
>
>
> 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