Skip to content

Commit 2d91fa8

Browse files
committed
fix: use the same rounding scheme for constants
ZX Spectrum ROM always rounds "towards -Infinity", so: * INT(1.9) == 1 * INT(-1.1) == -2 We do the same for Constant values so the results are consistent.
1 parent 951f53e commit 2d91fa8

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/symbols/typecast.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# See the file CONTRIBUTORS.md for copyright details.
55
# See https://www.gnu.org/licenses/agpl-3.0.html for details.
66
# --------------------------------------------------------------------
7+
import math
78

89
from src.api import check, errmsg
910
from src.api.errmsg import error
@@ -91,7 +92,8 @@ def make_node(cls, new_type: SymbolTYPE, node: Symbol, lineno: int):
9192
elif new_type.is_basic and not TYPE.is_integral(new_type): # not an integer
9293
node.value = float(node.value)
9394
else: # It's an integer
94-
new_val = int(node.value) & ((1 << (8 * new_type.size)) - 1) # Mask it
95+
# ZX Spectrum ROM always truncates to -Infinity, so we do the same using floor()
96+
new_val = math.floor(node.value) & ((1 << (8 * new_type.size)) - 1) # Mask it
9597

9698
if node.value >= 0 and node.value != new_val:
9799
errmsg.warning_conversion_lose_digits(node.lineno)

0 commit comments

Comments
 (0)