The operator involved in the opAssign operation
The left-hand side type of the operator (Lhs is the first argument to Checked)
The right-hand side type in the operator
The saturated result of the operator.
assert(checked!Saturate(int.max) + 1 == int.max); assert(checked!Saturate(100) ^^ 10 == int.max); assert(checked!Saturate(-100) ^^ 10 == int.max); assert(checked!Saturate(100) / 0 == int.max); assert(checked!Saturate(100) << -1 == 0); assert(checked!Saturate(100) << 33 == int.max); assert(checked!Saturate(100) >> -1 == int.max); assert(checked!Saturate(100) >> 33 == 0);
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: