src/intops/ops/sub

Source   Edit  

Templates

template borrow(a, b: SomeSignedInt; borrow: bool): bool

Borrowing subtraction that returns just the borrow flag for signed integers.

See also:

Source   Edit  
template borrow(a, b: SomeUnsignedInt; borrow: bool): bool

Borrowing subtraction that returns just the borrow flag for unsigned integers.

See also:

Source   Edit  
template borrowingSub(a, b: int32; borrow: bool): tuple[res: int32, borrow: bool]

Borrowing subtraction for signed 32-bit integers.

Takes two integers and returns their difference along with the borrow flag (BF): true means the previous subtraction had overflown, false means it hadn't.

Useful for chaining operations.

See also:

Source   Edit  
template borrowingSub(a, b: int64; borrow: bool): tuple[res: int64, borrow: bool]

Borrowing subtraction for signed 64-bit integers.

Takes two integers and returns their difference along with the borrow flag (BF): true means the previous subtraction had overflown, false means it hadn't.

Useful for chaining operations.

See also:

Source   Edit  
template borrowingSub(a, b: uint32; borrow: bool): tuple[res: uint32,
    borrow: bool]

Borrowing subtraction for unsigned 32-bit integers.

Takes two integers and returns their difference along with the borrow flag (BF): true means the previous subtraction had overflown, false means it hadn't.

Useful for chaining operations.

See also:

Source   Edit  
template borrowingSub(a, b: uint64; borrow: bool): tuple[res: uint64,
    borrow: bool]

Borrowing subtraction for unsigned 64-bit integers.

Takes two integers and returns their difference along with the borrow flag (BF): true means the previous subtraction had overflown, false means it hadn't.

Useful for chaining operations.

See also:

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

Overflowing subtraction.

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

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

See also:

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

Saturating subtraction.

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

See also:

Source   Edit