fix: treat `bool`s as `int`s in arithmetic expressions.

Merged
JA
2mo ago
+487-69

Fixes: #963

Treat boolean operands as integers when doing arithmetic calculations (addition, subtraction, etc).

Using immediate_int and immediate_float helper for basic arithmetic.

Using py_float_divmod for correct // behaviour.

Simplifying pow when the base value is a boolean.


Summary by cubic

Makes arithmetic operations treat bool operands as integers (True = 1, False = 0), fixing #963.

  • +, -, and % now accept bool/int/float combinations and return the same types as CPython.
  • // uses py_float_divmod so float floor division matches divmod semantics, including special values like infinity and NaN.
  • bool ** int with a nonnegative exponent simplifies to 0 or 1 without overflow, matching CPython.
  • Adds a test file covering bool operands across arithmetic, overflow boundaries, augmented assignment, and truthiness in sum() patterns.