示例#1
0
 def __new__(cls, val=fzero, **kwargs):
     """A new mpf can be created from a Python float, an int, a
     or a decimal string representing a number in floating-point
     format."""
     prec, rounding = prec_rounding
     if kwargs:
         prec = kwargs.get('prec', prec)
         if 'dps' in kwargs:
             prec = dps_to_prec(kwargs['dps'])
         rounding = kwargs.get('rounding', rounding)
     if type(val) is cls:
         sign, man, exp, bc = val._mpf_
         if (not man) and exp:
             return val
         return make_mpf(normalize(sign, man, exp, bc, prec, rounding))
     elif type(val) is tuple:
         if len(val) == 2:
             return make_mpf(from_man_exp(val[0], val[1], prec, rounding))
         if len(val) == 4:
             sign, man, exp, bc = val
             return make_mpf(normalize(sign, MP_BASE(man), exp, bc, prec, rounding))
         raise ValueError
     else:
         return make_mpf(mpf_pos(mpf_convert_arg(val, prec, rounding), prec, rounding))
示例#2
0
 def __call__(self, prec=None, dps=None, rounding=None):
     if not prec: prec = prec_rounding[0]
     if not rounding: rounding = prec_rounding[1]
     if dps: prec = dps_to_prec(dps)
     return make_mpf(self.func(prec, rounding))