Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
public static int multAccum(int oldAcc, int newVal, int scale)
                  throws ArithmeticException {
  return safeAdd(oldAcc, safeMultiply(newVal, scale));
}

Compliant Solution (Java 8, Math.*

...

Exact())

This compliant solution uses the addExact() and multiplyExact() methods defined in the Math class. These methods were added to Java as part of the Java 8 release, and they also either return a mathematically correct value or throw ArithmeticException. The Math class also provides SubtractExact() and negateExact(), but does not provide any methods for safe division or absolute value.

...

...

 

...

Rule 03. : Numeric Types and Operations (NUM)      Rule 03. : Numeric Types and Operations (NUM)