src/intops/ops/add

Source   Edit  

Templates

template carryingAdd(a, b: int32; carryIn: bool): tuple[res: int32,
    carryOut: bool]

Carrying addition for signed 32-bit integers.

Takes two integers and returns their sum along with the carrying flag (CF): true means the previous addition had overflown, false means it hadn't.

Useful for chaining operations.

See also:

Source   Edit  
template carryingAdd(a, b: int64; carryIn: bool): tuple[res: int64,
    carryOut: bool]

Carrying addition for signed 64-bit integers.

Takes two integers and returns their sum along with the carrying flag (CF): true means the previous addition had overflown, false means it hadn't.

Useful for chaining operations.

See also:

Source   Edit  
template carryingAdd(a, b: uint32; carryIn: bool): tuple[res: uint32,
    carryOut: bool]

Carrying addition for unsigned 32-bit integers.

Takes two integers and returns their sum along with the carrying flag (CF): true means the previous addition had overflown, false means it hadn't.

Useful for chaining operations.

See also:

Source   Edit  
template carryingAdd(a, b: uint64; carryIn: bool): tuple[res: uint64,
    carryOut: bool]

Carrying addition for unsigned 64-bit integers.

Takes two integers and returns their sum along with the carrying flag (CF): true means the previous addition had overflown, false means it hadn't.

Useful for chaining operations.

See also:

Source   Edit  
template overflowingAdd[T: SomeInteger](a, b: T): tuple[res: T,
    didOverflow: bool]

Overflowing addition.

Takes two integers and returns their sum along with the overflow flag (OF): true means overflow happened, false means overflow didn't happen.

Addition wraps for both signed and unsigned integers, so this operation never raises.

See also:

Source   Edit  
template saturatingAdd[T: SomeInteger](a, b: T): T

Saturating addition.

Takes two integers and returns their sum; if the result won't fit within the type, the maximal possible value is returned.

See also:

Source   Edit