> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go Subtraction

The `-` operator in Go functions as both a binary arithmetic operator for subtraction and a unary arithmetic operator for numeric negation. It operates exclusively on numeric types, including signed and unsigned integers, floating-point numbers, and complex numbers.

## Binary Subtraction

As a binary operator, `-` computes the difference between two operands. Go enforces strict type safety; both operands must be of the exact same concrete type, or be untyped constants representable by the target type. Go does not perform implicit type coercion.

```go theme={"dark"}
var a int32 = 42
var b int32 = 10
diff := a - b // Valid: both are int32

var c float64 = 5.5
// invalid := a - c // Compilation error: mismatched types int32 and float64
```

When operating on untyped numeric constants, the `-` operator yields an untyped constant. The default type of the result is determined by the operands (e.g., subtracting two untyped integers yields an untyped integer).

```go theme={"dark"}
const x = 10 - 3.0 // Untyped floating-point constant, value 7.0
```

## Unary Negation

As a unary operator, `-` yields the arithmetic inverse of its single operand.

```go theme={"dark"}
var x int = 15
negX := -x // Value: -15

var y complex64 = 3 + 4i
negY := -y // Value: -3 - 4i
```

Applying the unary `-` to an unsigned integer type is syntactically valid. It computes the two's complement negation of the value, which effectively results in a wrap-around based on the bit-width of the unsigned type.

```go theme={"dark"}
var u uint8 = 1
negU := -u // Type: uint8, Value: 255 (binary 11111111)
```

## Overflow and Underflow Mechanics

Go handles arithmetic underflow and overflow silently at runtime without panicking.

* **Integers:** Subtracting past the minimum value of a signed or unsigned integer type results in a silent two's complement wrap-around.
* **Floating-point:** Subtraction adheres to IEEE-754 standards. Subtracting values that exceed the precision or range limits will result in `-Inf` (negative infinity) or `NaN` (Not a Number), depending on the operands.

```go theme={"dark"}
// Integer underflow
var minVal uint8 = 0
wrap := minVal - 1 // Value: 255

// Floating-point infinity
var f1 float64 = -1e308
var f2 float64 = 1e308
infResult := f1 - f2 // Value: -Inf
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Go Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
