-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Labels
Description
Bug report
Problem
MOD operator returns wrong results with negative argument.
Steps
- Run PC-BASIC
- Enter the following and press
Enter
for i=-5 to 3: ? i mod 2; : next - Observed:
-1 -2 -1 -2 -1 0 1 0 1 - Expected:
-1 0 -1 0 -1 0 1 0 1 - Compare with GW-BASIC from MS-DOS (in DOSBox)
Note: Python works as expected:
>>> [x % 2 for x in range(-5,3)]
[1, 0, 1, 0, 1, 0, 1, 0]
The problem is in the source pcbasic\basic\values\numbers.py:
if dividend < 0 or mod < 0: mod -= divisor
It should be
mod = -mod
Program
This affects an existing program, which calculates coordinate offset.
Notes
PC-BASIC version: 2.0.7
Operating system version: Windows 11 64-bit
tingtron