def interpolate_value_token(s1, s2, pos, mod=0):
    """ If the values are floats, returns the linear interpolation of them
        at position pos.  If they're strings, but the same, returns the string.
        If they're different, raises an exception.
        
        The mod argument is for spaces that wrap around, like rotation.  If 
        we're interpolating two values measured by degrees, we want to
        interpret both the inputs and the result by modulus 360."""

    v1, v2 = 0.0, 0.0
    assert(mod >= 0)
    try:
        v1 = float(s1)
        v2 = float(s2)
        if mod:
            # note that Python negative mod makes this work; may not work
            # the same in other languages
            v1 %= mod
            v2 %= mod
            if abs(v1 + mod - v2) < abs(v1 - v2):
                v1 += mod
            if abs(v2 + mod - v1) < abs(v2 - v1):
                v2 += mod
        interpolation = v1 + pos * (v2 - v1)
        if mod:
            interpolation %= mod
        return "{:.3f}".format(interpolation)
    except ValueError:
        if s1 == s2:
            return s1 
        else:
            raise Exception("Cannot interpolate between %s and %s", (s1, s2))