Integer Overflow Intrinsics (The GNU D Compiler)

#### 2.5.2 Integer Overflow Intrinsics ¶

The following functions are a collection of intrinsics that implement integral arithmetic primitives that check for out-of-range results, available by importing the `core.checkedint` module.

In all intrinsics, the overflow is sticky, meaning a sequence of operations can be done and overflow need only be checked at the end.

Function: `int` core.checkedint.adds `(int x, int y, ref bool overflow)` ¶
Function: `long` core.checkedint.adds `(long x, long y, ref bool overflow)` ¶

  Add two signed integers, checking for overflow.

  This intrinsic is the same as the GCC built-in function `__builtin_sadd_overflow`.

Function: `int` core.checkedint.addu `(int x, int y, ref bool overflow)` ¶
Function: `long` core.checkedint.addu `(long x, long y, ref bool overflow)` ¶

  Add two unsigned integers, checking for overflow.

  This intrinsic is the same as the GCC built-in function `__builtin_uadd_overflow`.

Function: `int` core.checkedint.muls `(int x, int y, ref bool overflow)` ¶
Function: `long` core.checkedint.muls `(long x, long y, ref bool overflow)` ¶

  Multiply two signed integers, checking for overflow.

  This intrinsic is the same as the GCC built-in function `__builtin_smul_overflow`.

Function: `int` core.checkedint.mulu `(int x, int y, ref bool overflow)` ¶
Function: `long` core.checkedint.mulu `(long x, long y, ref bool overflow)` ¶

  Multiply two unsigned integers, checking for overflow.

  This intrinsic is the same as the GCC built-in function `__builtin_umul_overflow`.

Function: `int` core.checkedint.negs `(int x, ref bool overflow)` ¶
Function: `long` core.checkedint.negs `(long x, ref bool overflow)` ¶

  Negates an integer.

  This intrinsic is equivalent to writing the following:

      result = __builtin_ssub (0, x, overflow);

Function: `int` core.checkedint.subs `(int x, int y, ref bool overflow)` ¶
Function: `long` core.checkedint.subs `(long x, long y, ref bool overflow)` ¶

  Subtract two signed integers, checking for overflow.

  This intrinsic is the same as the GCC built-in function `__builtin_ssub_overflow`.

Function: `int` core.checkedint.subu `(int x, int y, ref bool overflow)` ¶
Function: `long` core.checkedint.subu `(long x, long y, ref bool overflow)` ¶

  Subtract two unsigned integers, checking for overflow.

  This intrinsic is the same as the GCC built-in function `__builtin_usub_overflow`.