Protocol std::builtins::internal::WithOverflow
Mixin for wrapping and checked arithmetic operations.
Provided methods
-
Adds two numbers, wrapping around at the boundary of the type.
-
Subtracts two numbers, wrapping around at the boundary of the type.
-
Multiplies two numbers, wrapping around at the boundary of the type.
-
Divides two numbers, wrapping around at the boundary of the type.
The only case where such wrapping can occur is when one divides
MIN / -1
on a signed type. This is equivalent to-MIN
, a number that is too large to represent in the type. In such a case, this function returnsMIN
itself. -
Tries to add two numbers, returning
Option::none()
if overflow occurrs. -
Tries to subtract two numbers, returning
Option::none()
if overflow occurrs. -
Tries to multiply two numbers, returning
Option::none()
if overflow occurrs. -
Tries to divide two numbers, returning
Option::none()
if overflow occurrs orrhs
is zero.Overflow during division can only happen when one divides
MIN / -1
on a signed type.