Op Thu, 05 Jan 2017 16:49:09 +0100 schreef Tobias Fröschle <tobias.froesc...@t-online.de>:

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 doing integer division. Different languages have made different choices. S*Basic designers have chosen to use the "flooring" approach (round the floating point result to the next smaller number).

Some other reasoning: -1 / 2 should be?
(1) -1/2 = 0 remainder -1
(2)$FFFF ASR 1 = $FFFF = -1

Another note: The original QL allowed word-size divisors and dividends. while SMSQ/E extended this to long integers. And the original QL manual even had an example illustrating what you see here:

-5 DIV 2 { will output -3}

A word of warning!

It may be true that SMSQ/E supports Long INTs for DIV/MOD but I do remember that QLIB does not. I tried this in SQRview and it worked fine in SBasic but needed a workaround for QLIB to avoid an "overflow" error.
It's possible that QLIB uses its own DIV/MOD routines.

Bob

--
The BSJR QL software site at: "http://members.upc.nl/b.spelten/ql/";
_______________________________________________
QL-Users Mailing List

Reply via email to