Esempio n. 1
0
def Int2FL(a, gamma, l, kappa):
    lam = gamma - 1
    s = types.sint()
    AdvInteger.LTZ(s, a, gamma, kappa)
    z = AdvInteger.EQZ(a, gamma, kappa)
    a = (1 - 2 * s) * a

    a_bits = AdvInteger.BitDec(a, lam, lam, kappa)
    a_bits.reverse()
    b = AdvInteger.PreOR(a_bits)
    t = a * (1 + sum(2**i * (1 - b_i) for i, b_i in enumerate(b)))
    p = -(lam - sum(b))
    if lam > l:
        if types.sfloat.round_nearest:
            v, overflow = TruncRoundNearestAdjustOverflow(
                t, gamma - 1, l, kappa)
            p = p + overflow
        else:
            v = types.sint()
            AdvInteger.Trunc(v, t, gamma - 1, gamma - l - 1, kappa, False)
            #TODO: Shouldnt this be only gamma
    else:
        v = 2**(l - gamma + 1) * t
    p = (p + gamma - 1 - l) * (1 - z)
    return v, p, z, s
Esempio n. 2
0
def floor_fx(x):
    return load_sint(AdvInteger.Trunc(x.v, x.k - x.f, x.f, x.kappa), type(x))