> ## 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 Unary Minus

The `-` operator in Go functions as both a binary arithmetic operator for subtraction and a unary arithmetic operator for numeric negation. It applies exclusively to numeric types (integer, floating-point, and complex numbers) and untyped numeric constants.

## Binary Subtraction

As a binary operator, `-` computes the difference between two operands.

```go theme={"dark"}
var a int32 = 15
var b int32 = 5
var difference int32 = a - b // Evaluates to 10
```

**Type Strictness:** Go requires both operands to be of the exact same type. The compiler does not perform implicit type coercion. If the operands are of different types, an explicit type conversion is required.

```go theme={"dark"}
var x int = 10
var y float64 = 3.5
// result := x - y // Compilation error: invalid operation: mismatched types int and float64
result := float64(x) - y
```

## Unary Negation

As a unary operator, `-` precedes a single operand and yields its arithmetic negation.

```go theme={"dark"}
var val float64 = 4.2
var neg float64 = -val // Evaluates to -4.2
```

## Arithmetic Mechanics and Edge Cases

**Integer Overflow and Underflow:**
Go does not panic on integer underflow or overflow. Arithmetic operations on integer types wrap around silently based on two's complement representation.

```go theme={"dark"}
var minInt8 int8 = -128
var underflow int8 = minInt8 - 1 // Evaluates to 127 (wraps to max int8)
```

**Unsigned Integer Negation and Subtraction:**
Subtracting a larger unsigned integer from a smaller one wraps around to the upper bound of the type's capacity. Applying the unary `-` operator to an unsigned integer `x` is mathematically defined as `2^n - x` (where `n` is the bit width of the type), effectively yielding the two's complement wrap-around value.

```go theme={"dark"}
var u uint8 = 0
var sub uint8 = u - 1 // Evaluates to 255

var v uint8 = 5
var negV uint8 = -v   // Evaluates to 251 (256 - 5)
```

**Floating-Point and Complex Numbers:**
For `float32`, `float64`, `complex64`, and `complex128`, the `-` operator strictly adheres to the IEEE-754 standard. This includes the correct handling of signed zeros (`-0.0`), Infinity (`+Inf`, `-Inf`), and Not-a-Number (`NaN`).

```go theme={"dark"}
var f1 float64 = math.Inf(1)
var f2 float64 = math.Inf(1)
var f3 float64 = f1 - f2 // Evaluates to NaN
```

**Untyped Constants:**
When the `-` operator is applied to untyped numeric constants, the operation is evaluated at compile-time with arbitrary precision, bypassing the size limitations and overflow characteristics of standard typed integers until the constant is assigned to a typed variable.

```go theme={"dark"}
const huge = 1 << 100
const diff = huge - (huge - 1) // Evaluates at compile-time to untyped constant 1
```

<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>
