from typing import Union
import math


def maybe_int(x: float, tol: float) -> Union[int, float]:
    """ Turn almost ints to actual ints, pass through other values unmodified
    """
    def split(x):
        x_part = math.fmod(x, 1.0)
        x_whole = x - x_part
        if x_part > 0.5:
            x_part -= 1
            x_whole += 1
        elif x_part < -0.5:
            x_part += 1
            x_whole -= 1
        return (x_whole, x_part)

    x_whole, x_part = split(x)

    if abs(x_part) < tol:  # almost int
        return int(x_whole)
    else:
        return x