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.max if the result overflows in the positive direction, on division by 0, or on shifting right by a negative value
  • Lhs.min if the result overflows in the negative direction
  • 0 if lhs is being shifted left by a negative value, or shifted right by a large positive value

Parameters

xThe operator involved in the opAssign operation
LhsThe left-hand side type of the operator (Lhs is the first argument to Checked)
RhsThe 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