Here you can find the source of minusExact(final int a, final int b)
Parameter | Description |
---|---|
a | An int value. |
b | An int value. |
Parameter | Description |
---|---|
ArithmeticException | if the mathematical result of a-b is not in [Integer.MIN_VALUE,Integer.MAX_VALUE] range. |
public static int minusExact(final int a, final int b)
//package com.java2s; //License from project: Open Source License public class Main { /**/* www . java2 s. c o m*/ * @param a * An int value. * @param b * An int value. * @return The mathematical result of a-b. * @throws ArithmeticException * if the mathematical result of a-b is not in [Integer.MIN_VALUE,Integer.MAX_VALUE] range. */ public static int minusExact(final int a, final int b) { final int diff = a - b; // HD 2-12 Overflow iff the arguments have different signs and // the sign of the result is different than the sign of "a". if (((a ^ b) & (a ^ diff)) < 0) { throw new ArithmeticException("integer overflow"); } return diff; } /** * @param a * A long value. * @param b * A long value. * @return The mathematical result of a-b. * @throws ArithmeticException * if the mathematical result of a-b is not in [Long.MIN_VALUE,Long.MAX_VALUE] range. */ public static long minusExact(final long a, final long b) { final long diff = a - b; // HD 2-12 Overflow iff the arguments have different signs and // the sign of the result is different than the sign of "a". if (((a ^ b) & (a ^ diff)) < 0) { throw new ArithmeticException("integer overflow"); } return diff; } }