Standard library / math/bits

bits.Sub()

Subtracts y and borrow-in (0 or 1) from x; returns low word and borrow-out. Native uint width is architecture-dependent; local validation uses 64 bits. Expected stdout: 'true 1\n'.

Formal Syntax & Structure

go syntaxgo
func Sub(x, y, borrow uint) (diff, borrowOut uint)

Parameters & Attributes

NameTypeDescription
xuintFirst input operand (or sole input if unary).
yuintSecond input operand.
borrowuintBorrow-in bit; must be 0 or 1.

Return Value

(diff, borrowOut uint)

Subtracts y and borrow-in (0 or 1) from x; returns low word and borrow-out. Native uint width is architecture-dependent; local validation uses 64 bits.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/bits")
func main() {  s, c := bits.Sub(0, 1, 0)  fmt.Println(s == ^uint(0), c)}
Go Reference