14"""helpers methods for the cp_model module."""
21INT_MIN = -9223372036854775808
22INT_MAX = 9223372036854775807
26 """Checks if the x is a boolean."""
27 if isinstance(x, bool):
29 if isinstance(x, np.bool_):
35 """Asserts that x is 0 or 1 and returns it as an int."""
36 if not isinstance(x, numbers.Integral):
37 raise TypeError(f
"Not a boolean: {x} of type {type(x)}")
39 if x_as_int < 0
or x_as_int > 1:
40 raise TypeError(f
"Not a boolean: {x}")
45 """Restrict v within [INT_MIN..INT_MAX] range."""
54 """Saturated arithmetics. Returns x - y truncated to the int64_t range."""
58 if x == INT_MAX
or x == INT_MIN:
59 raise OverflowError(
"Integer NaN: subtracting INT_MAX or INT_MIN to itself")
61 if x == INT_MAX
or x == INT_MIN: