WithNaN.hookOpBinary

Defines hooks for binary operators +, -, *, /, %, ^^, &, |, ^, <<, >>, and >>> for cases where a Checked object is the left-hand side operand. If lhs == WithNaN.defaultValue!Lhs, returns WithNaN.defaultValue!(typeof(lhs + rhs)) without evaluating the operand. Otherwise, evaluates the operand. If evaluation does not overflow, returns the result. Otherwise, returns WithNaN.defaultValue!(typeof(lhs + rhs)).

struct WithNaN
static
hookOpBinary
(
string x
L
R
)
(
L lhs
,
R rhs
)

Parameters

x

The operator symbol

lhs L

The left-hand side operand (Lhs is the first argument to Checked)

rhs R

The right-hand side operand

Return Value

Type: auto

If lhs != WithNaN.defaultValue!Lhs and the operator does not overflow, the function returns the same result as the built-in operator. In all other cases, returns WithNaN.defaultValue!(typeof(lhs + rhs)).

Examples

Checked!(int, WithNaN) x;
assert((x + 1).isNaN);
x = 100;
assert(!(x + 1).isNaN);

Meta