Python decimal 模块,Overflow() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用decimal.Overflow()

项目:kodi-bandcamp    作者:wallon-ines    | 项目源码 | 文件源码
def make_decimal( self, s, sign='+' ):
        """Converts a string into a decimal or float value."""
        if not decimal or self.float_type == NUMBER_FLOAT:
            return self.make_float( s, sign )

        if s.startswith('-') or s.startswith('+'):
            sign = s[0]
            s = s[1:]
        elif isinstance(sign, (int,long)):
            if sign < 0:
                sign = '-'
            else:
                sign = '+'

        try:
            f = self.decimal_context.create_decimal( s )
        except decimal.InvalidOperation:
            f = self.decimal_context.create_decimal( 'NaN' )
        except decimal.Overflow:
            if sign=='-':
                f = self.decimal_context.create_decimal( '-Infinity' )
            else:
                f = self.decimal_context.create_decimal( 'Infinity' )
        else:
            if sign=='-':
                f = f.copy_negate()
        return f