def test_mpmath_issues(): from sympy.mpmath.libmp.libmpf import _normalize import sympy.mpmath.libmp as mlib rnd = mlib.round_nearest mpf = (0, long(0), -123, -1, 53, rnd) # nan assert _normalize(mpf, 53) != (0, long(0), 0, 0) mpf = (0, long(0), -456, -2, 53, rnd) # +inf assert _normalize(mpf, 53) != (0, long(0), 0, 0) mpf = (1, long(0), -789, -3, 53, rnd) # -inf assert _normalize(mpf, 53) != (0, long(0), 0, 0) from sympy.mpmath.libmp.libmpf import fnan assert mlib.mpf_eq(fnan, fnan)
def __ne__(self, other): try: other = _sympify(other) except SympifyError: return True # sympy != other if isinstance(other, NumberSymbol): if other.is_irrational: return True return other.__ne__(self) if isinstance(other, FunctionClass): #cos as opposed to cos(x) return True if isinstance(other, Number): return bool(not mlib.mpf_eq(self._mpf_, other._as_mpf_val(self._prec))) return True # Real != non-Number
def __eq__(self, other): try: other = _sympify(other) except SympifyError: return False # sympy != other --> not == if isinstance(other, NumberSymbol): if other.is_irrational: return False return other.__eq__(self) if isinstance(other, FunctionClass): #cos as opposed to cos(x) return False if other.is_comparable: other = other.evalf() if isinstance(other, Number): return bool(mlib.mpf_eq(self._mpf_, other._as_mpf_val(self._prec))) return False # Real != non-Number
def __ne__(self, other): try: other = _sympify(other) except SympifyError: return True # sympy != other if isinstance(other, NumberSymbol): if other.is_irrational: return True return other.__ne__(self) if isinstance(other, FunctionClass): #cos as opposed to cos(x) return True if other.is_comparable: other = other.evalf() if isinstance(other, Number): return bool(not mlib.mpf_eq(self._mpf_, other._as_mpf_val(self._prec))) return True # Real != non-Number
def __ne__(self, other): try: other = _sympify(other) except SympifyError: return True # sympy != other if isinstance(other, NumberSymbol): if other.is_irrational: return True return other.__ne__(self) if isinstance(other, FunctionClass): #cos as opposed to cos(x) return True if other.is_comparable and not isinstance(other, Rational): other = other.evalf() if isinstance(other, Number): if isinstance(other, Real): return bool(not mlib.mpf_eq(self._as_mpf_val(other._prec), other._mpf_)) return bool(self.p!=other.p or self.q!=other.q) return True # Rational != non-Number
def __eq__(self, other): try: other = _sympify(other) except SympifyError: return False # sympy != other --> not == if isinstance(other, NumberSymbol): if other.is_irrational: return False return other.__eq__(self) if isinstance(other, FunctionClass): #cos as opposed to cos(x) return False if other.is_comparable and not isinstance(other, Rational): other = other.evalf() if isinstance(other, Number): if isinstance(other, Real): return bool(mlib.mpf_eq(self._as_mpf_val(other._prec), other._mpf_)) return bool(self.p==other.p and self.q==other.q) return False # Rational != non-Number