- libisl.isl_val_free(self)
- self.context # prevents context from being GC'ed before the value
-
- @property
- def numerator(self):
- if self._numerator is None:
- raise ValueError('not a rational number')
- return self._numerator
-
- @property
- def denominator(self):
- if self._denominator is None:
- raise ValueError('not a rational number')
- return self._denominator
-
- def __bool__(self):
- return not bool(libisl.isl_val_is_zero(self))
-
- @_polymorphic_method
- def __lt__(self, other):
- return bool(libisl.isl_val_lt(self, other))
-
- @_polymorphic_method
- def __le__(self, other):
- return bool(libisl.isl_val_le(self, other))
-
- @_polymorphic_method
- def __gt__(self, other):
- return bool(libisl.isl_val_gt(self, other))
-
- @_polymorphic_method
- def __ge__(self, other):
- return bool(libisl.isl_val_ge(self, other))
-
- @_polymorphic_method
- def __eq__(self, other):
- return bool(libisl.isl_val_eq(self, other))
-
- # __ne__ is not implemented, ISL semantics does not match Python's on
- # nan != nan
-
- def __abs__(self):
- val = libisl.isl_val_copy(self)
- val = libisl.isl_val_abs(val)
- return self.__class__(self.context, self._ptr(val))
-
- def __pos__(self):
- return self
-
- def __neg__(self):
- val = libisl.isl_val_copy(self)
- val = libisl.isl_val_neg(val)
- return self.__class__(self.context, self._ptr(val))
-
- def __floor__(self):
- val = libisl.isl_val_copy(self)
- val = libisl.isl_val_floor(val)
- return self.__class__(self.context, self._ptr(val))
-
- def __ceil__(self):
- val = libisl.isl_val_copy(self)
- val = libisl.isl_val_ceil(val)
- return self.__class__(self.context, self._ptr(val))
-
- def __trunc__(self):
- val = libisl.isl_val_copy(self)
- val = libisl.isl_val_trunc(val)
- return self.__class__(self.context, self._ptr(val))
-
- @_polymorphic_method
- def __add__(self, other):
- val1 = libisl.isl_val_copy(self)
- val2 = libisl.isl_val_copy(other)
- val = libisl.isl_val_add(val1, val2)
- return self.__class__(self.context, self._ptr(val))
-
- __radd__ = __add__
-
- @_polymorphic_method
- def __sub__(self, other):
- val1 = libisl.isl_val_copy(self)
- val2 = libisl.isl_val_copy(other)
- val = libisl.isl_val_sub(val1, val2)
- return self.__class__(self.context, self._ptr(val))
-
- __rsub__ = __sub__
-
- @_polymorphic_method
- def __mul__(self, other):
- val1 = libisl.isl_val_copy(self)
- val2 = libisl.isl_val_copy(other)
- val = libisl.isl_val_mul(val1, val2)
- return self.__class__(self.context, self._ptr(val))
-
- __rmul__ = __mul__
-
- @_polymorphic_method
- def __truediv__(self, other):
- val1 = libisl.isl_val_copy(self)
- val2 = libisl.isl_val_copy(other)
- val = libisl.isl_val_div(val1, val2)
- return self.__class__(self.context, self._ptr(val))
-
- __rtruediv__ = __truediv__
-
- def __float__(self):
- if libisl.isl_val_is_rat(self):
- return self.numerator / self.denominator
- elif libisl.isl_val_is_infty(self):
- return float('inf')
- elif libisl.isl_val_is_neginfty(self):
- return float('-inf')
- else:
- assert libisl.isl_val_is_nan(self)
- return float('nan')
-
- def is_finite(self):
- return bool(libisl.isl_val_is_rat(self))
-
- def is_infinite(self):
- return bool(libisl.isl_val_is_infty(self) or
- libisl.isl_val_is_neginfty(self))
-
- def is_nan(self):
- return bool(libisl.isl_val_is_nan(self))
-
- def __str__(self):
- if libisl.isl_val_is_rat(self):
- if self.denominator == 1:
- return '{}'.format(self.numerator)
- else:
- return '{}/{}'.format(self.numerator, self.denominator)
- elif libisl.isl_val_is_infty(self):
- return 'Infinity'
- elif libisl.isl_val_is_neginfty(self):
- return '-Infinity'
- else:
- assert libisl.isl_val_is_nan(self)
- return 'NaN'