Arithmetic Operations and Edge Cases
The advantage of the arithmetical operators like .plus()
, .minus()
, .multiply()
etc... is that they handle for you the different types that can be in the data in an efficient way, and they help CoPPer understand your business logic so that it can optimize it.
Their behavior is straight-forward based on their name, but we have to explain what happens in the edge cases: when an operand is null or equal to zero for instance:
Operation | a is null | b is null | b is zero |
---|---|---|---|
a.plus(b) | returns null | returns null | returns a |
a.minus(b) | returns null | returns null | returns a |
a.multiply(b) | returns null | returns null | returns 0 |
a.divide(b) | returns null | returns null | Throws an ArithmeticException at query time |
Which can be summarized by: Even in CoPPer, never divide by zero, otherwise if any operand is missing we return null.