def roundval(val, reltol=0.01):
    """Calcul d'une valeur arrondie proche a reltol pres"""
    from math import log
    tol = reltol * abs(val)
    d = log(tol, 10.0) + 0.0001
    n = int(d)
    if n < 0:
        n -= 1
    base = 10 ** n
    rest = tol / base + 0.0001
    for x in (7.5, 5.0, 4.0, 2.5, 2.0, 1.5, 1.0):
        if x <= rest:
            break
    rest = base * x
    r1 = rest * (val // rest)
    if val >= 0.0:
        r2 = r1 + rest
    else:
        r1, r2 = r1 - rest, r1
    r3 = r1 if r2 - val > val - r1 else r2
    return r1, r3, r2
