Standard library / math/bits

bits.Sub64()

Subtracts y and borrow-in (0 or 1) from x; returns low word and borrow-out. Expected stdout: 'true 1\n'.

Formal Syntax & Structure

go syntaxgo
func Sub64(x, y, borrow uint64) (diff, borrowOut uint64)

Parameters & Attributes

NameTypeDescription
xuint64First input operand (or sole input if unary).
yuint64Second input operand.
borrowuint64Borrow-in bit; must be 0 or 1.

Return Value

(diff, borrowOut uint64)

Subtracts y and borrow-in (0 or 1) from x; returns low word and borrow-out.

Working Example

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