For the int version, that would be better replaced with something like

    return ((value - min) % (max - min)) + min;

Note that is just off the top of my head, so it may contain bugs, but is
along the lines of how it should be written.