The OpenD Programming Language

Saturate.onLowerBound

Implements saturation for operators +=, -=, *=, /=, %=, ^^=, &=, |=, ^=, <<=, >>=, and >>>=. This hook is called if the result of the binary operation does not fit in Lhs without loss of information or a change in sign.

  1. T onLowerBound(Rhs , T bound)
    struct Saturate
    static
    T
    onLowerBound
    (
    Rhs
    T
    )
    (
    Rhs
    ,)
  2. T onUpperBound(Rhs , T bound)

Parameters

Rhs

The right-hand side type in the assignment, after the operation has been computed

bound T

The bound being violated

Return Value

Type: T

Lhs.max if rhs >= 0, Lhs.min otherwise.

Examples

auto x = checked!Saturate(short(100));
x += 33000;
assert(x == short.max);
x -= 70000;
assert(x == short.min);

Meta