Skip to content

Integer functions

Adds support (freezing, typing, printing) for the following integer functions from sympyextensions.integer_functions:

  • bit_shift_left
  • bit_shift_right
  • bitwise_and
  • bitwise_or
  • bitwise_xor
  • int_div
  • int_power_of_2
  • modulo_floor

The following are left for future work because they can be conveniently implemented with an if expression (the ternary if operator ?: in C) which is currently not available.

  • modulo_ceil
  • div_ceil

div_floor is also not implemented because to me the semantics of this function are unclear. Is it supposed to compute \lfloor \frac ab \rfloor (as the name suggests) or the C-like round-to-zero integer division (as the documentation suggests)?

The typifier tries to infer the integer type of the arguments/result and always raises if the type is non-integer. Note that this can lead to cases in which an exception is raised because the inference fails. For example int_div(2, 3) where both arguments are untyped constants. This could be improved in the typifier, e.g. by adding type constraints to deferred constants (also left for future work).

Edited by Daniel Bauer

Merge request reports