var.opBinary

var opBinary(string op)(const var rhs) if (op == "+" || op == "-" || op == "*" || op == "/" || op == "%") const @safe

Binary arithmetic operators for var.

Supported operators: `+`, `-`, `*`, `/`, `%`

Type promotion rules:

  • If either operand is DOUBLE, FLOAT, or REAL, the result is DOUBLE.
  • If either operand is ULONG and the other is unsigned or fits, result is ULONG.
  • Otherwise (any signed or smaller integer types), the computation is done in long and the result is LONG.
  • For non-numeric types (NULL, STRING, ARRAY, OBJECT, CHAR, WCHAR, DCHAR, BOOL), the operation returns var.init (NULL).

    Parameters

    opThe binary operator (`"+"`, `"-"`, `"*"`, `"/"`, `"%"`).
    rhsThe right-hand side operand.

    Returns

    A new var containing the result of the operation, or var.init if the operation is not supported for the given types.
  • Notes:
  • Integer division/modulo by zero returns var.init (NULL) instead of silently
  • yielding 0. Signed division overflow (long.min / -1) also returns
  • var.init because 9223372036854775808 is not representable; the
  • remainder of the same pair is the exact 0. *
  • Mixed signed/unsigned integer operands with a magnitude above
  • long.max compute exactly whenever the result is representable in
  • the 64-bit integer domain (addition always is; subtraction,
  • multiplication, and division carry explicit overflow checks; modulo
  • always is). Only genuinely unrepresentable results (for example
  • ulong.max - (-1) = 2^64) use the documented double approximation.

With at least one FIXED_DECIMAL operand, `+ - * /` run in the wide decimal form (integral operands convert exactly; results box FIXED_DECIMAL; value errors throw; float/text mixes yield NULL — see doc/DDN-DECIMAL-ARITHMETIC.md D7).