Saturate.onOverflow
auto onOverflow(string x, Lhs)(Lhs)Implements saturation for operators `+`, `-` (unary and binary), `*`, `/`, `%`, `^^`, `&`, `|`, `^`, `<<`, `>>`, and `>>>`.
For unary `-`, onOverflow is called if lhs == Lhs.min and Lhs is a signed type. The function returns Lhs.max.
For binary operators, the result is as follows:
Lhs.maxif the result overflows in the positive direction, on division by0, or on shifting right by a negative valueLhs.minif the result overflows in the negative direction0iflhsis being shifted left by a negative value, or shifted right by a large positive value
Parameters
x | The operator involved in the opAssign operation |
Lhs | The left-hand side type of the operator (Lhs is the first argument to Checked) |
Rhs | The right-hand side type in the operator |
Returns
The saturated result of the operator.
typeof(Lhs() + Rhs()) onOverflow(string x, Lhs, Rhs)(Lhs lhs, Rhs rhs)ditto