MCPcopy Create free account
hub / github.com/MenoData/Time4J / safeSubtract

Method safeSubtract

base/src/main/java/net/time4j/base/MathUtils.java:171–194  ·  view source on GitHub ↗
(
        int op1,
        int op2
    )

Source from the content-addressed store, hash-verified

169 * @throws ArithmeticException if int-range overflows
170 */
171 public static int safeSubtract(
172 int op1,
173 int op2
174 ) {
175
176 if (op2 == 0) {
177 return op1;
178 }
179
180 long result = ((long) op1) - ((long) op2);
181
182 if ((result < Integer.MIN_VALUE) || (result > Integer.MAX_VALUE)) {
183 StringBuilder sb = new StringBuilder(32);
184 sb.append("Integer overflow: (");
185 sb.append(op1);
186 sb.append(',');
187 sb.append(op2);
188 sb.append(')');
189 throw new ArithmeticException(sb.toString());
190 } else {
191 return (int) result;
192 }
193
194 }
195
196 /**
197 * <p>Subtracts the numbers from each other with range check. </p>

Callers 15

betweenMethod · 0.95
withValueMethod · 0.95
withValueMethod · 0.95
betweenMethod · 0.95
withValueMethod · 0.95
withMethod · 0.95
readJulianMethod · 0.95
transformMethod · 0.95
transformMethod · 0.95
toProlepticYearMethod · 0.95
toIsoYearMethod · 0.95

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected