Esempio n. 1
0
def randcontext(exprange):
    c = Context(C.Context(), P.Context())
    c.Emax = random.randrange(1, exprange + 1)
    c.Emin = random.randrange(-exprange, 0)
    maxprec = 100 if c.Emax >= 100 else c.Emax
    c.prec = random.randrange(1, maxprec + 1)
    c.clamp = random.randrange(2)
    c.clear_traps()
    return c
Esempio n. 2
0
 def __init__(self):
     self.ulpdiff = 0
     self.powmod_zeros = 0
     self.maxctx = P.Context(Emax=10**18, Emin=-10**18)
Esempio n. 3
0
            if self.c.flags[signal] == (not self.p.flags[CondMap[signal]]):
                return False
        return True


# We don't want exceptions so that we can compare the status flags.
context = Context()
context.Emin = C.MIN_EMIN
context.Emax = C.MAX_EMAX
context.clear_traps()

# When creating decimals, _decimal is ultimately limited by the maximum
# context values. We emulate this restriction for decimal.py.
maxcontext = P.Context(prec=C.MAX_PREC,
                       Emin=C.MIN_EMIN,
                       Emax=C.MAX_EMAX,
                       rounding=P.ROUND_HALF_UP,
                       capitals=1)
maxcontext.clamp = 0


def RestrictedDecimal(value):
    maxcontext.traps = copy(context.p.traps)
    maxcontext.clear_flags()
    if isinstance(value, str):
        value = value.strip()
    dec = maxcontext.create_decimal(value)
    if maxcontext.flags[P.Inexact] or \
       maxcontext.flags[P.Rounded] or \
       maxcontext.flags[P.Clamped] or \
       maxcontext.flags[P.InvalidOperation]: