decimal.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:datatest 作者: shawnbrown 项目源码 文件源码
def _convert_for_comparison(self, other, equality_op=False):
        if isinstance(other, Decimal):
            return self, other
        if isinstance(other, _numbers.Rational):
            if not self._is_special:
                self = _dec_from_triple(self._sign,
                                        str(int(self._int) * other.denominator),
                                        self._exp)
            return self, Decimal(other.numerator)
        if equality_op and isinstance(other, _numbers.Complex) and other.imag == 0:
            other = other.real
        if isinstance(other, float):
            context = getcontext()
            if equality_op:
                context.flags[FloatOperation] = 1
            else:
                context._raise_error(FloatOperation,
                    "strict semantics for mixing floats and Decimals are enabled")
            return self, Decimal.from_float(other)
        return NotImplemented, NotImplemented
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号