class MathUtil {

    public static int subtractSafe(int a, int b)
    {
        int r = a - b;
        if (((a ^ b) & (a ^ r)) < 0)
        {
            return a < 0 ? Integer.MIN_VALUE : Integer.MAX_VALUE;
        }
        return r;
    }

    private  MathUtil();

}