pawn-lang/compiler

Incorrect division of integers in special cases

MuthaX opened this issue · 1 comments

Issue description:

I don’t know exactly how it is related is for the compiler or not.
If you divide one INTEGER number by another INTEGER, then in some cases you can get strange results.
This issue appears only at runtime. The code (with const values) that was optimised at compile-time works perfectly.

If you divide some positive integer N (>0xFFFF) by any integer M from range (represented in hex as) [0x0x7FFF3BB7 - 0x7FFFFFF] you will get result = 1 (expected 0 if +N<M and 1 otherwise).
Dividing N by M=[0x0 - 0x7FFF3BB6] works as expected.
Dividing N by M=0x8000000 will give you result = 1 (expected 0).
Dividing N by any integer from range M=[(-N-1) - (cellmin+1)] will give you result = -1 (expected 0).

Minimal complete verifiable example (MCVE):

new N, M, Res;
N=100500; M=0x7FFF3BB6; Res=N/M; // resulted as 0, expected 0. OK.
N=100500; M=0x7FFF3BB7; Res=N/M; // resulted as -1, expected 0.
N=100500; M=0x7FFFFFFF; Res=N/M; // resulted as -1, expected 0.
N=100500;M=0x80000000; Res=N/M; // resulted as 1, expected 0.
N=100;M=-128; Res=N/M; // resulted as -1, expected 0.
The next examples works as expected (cause of right optimisation of compiler).
Res=100500/0x7FFF3BB7;
Res=100500/0x7FFF3BB6;
Res=100500/0x7FFFFFFF;
Res=100500/0x7FFF3BB7;
Res=100500/0x80000000;
Res=100/-128;

Workspace Information:

  • Compiler version: 3.9 - 3.10.10
  • Command line arguments provided (or sampctl version):
  • Operating System: Windows 10 (may be machine related).
stale commented

This issue has been automatically marked as stale because it has not had recent activity.