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

The `%` operator in Go is the arithmetic remainder operator. It yields the remainder of the division between two integer operands.

```go theme={"dark"}
package main

import "fmt"

func main() {
    dividend := 10
    divisor := 3
    result := dividend % divisor
    
    fmt.Println(result) // Output: 1
}
```

## Type Constraints

In Go, the `%` operator is strictly restricted to integer types (`int`, `int8`, `int16`, `int32`, `int64`, `uint`, `uint8`, `uint16`, `uint32`, `uint64`, `uintptr`, `byte`, `rune`).

Attempting to use the `%` operator with floating-point numbers (`float32`, `float64`) or complex numbers results in an "operator not defined" compile-time error (e.g., `invalid operation: a % b (operator % not defined on float64)`). To calculate the remainder of floating-point numbers, Go requires the `math.Mod` function from the standard library.

## Mathematical Behavior and Sign Rules

Go implements truncated division (rounding toward zero). Because of this, the `%` operator in Go is technically a *remainder* operator, not a strict mathematical *modulo* operator.

The behavior of `%` is formally defined by the following equation:

`(a / b) * b + (a % b) == a`

A critical characteristic of Go's remainder operator is that **the sign of the result always matches the sign of the dividend** (the left operand). The sign of the divisor (the right operand) has no effect on the sign of the result.

```go theme={"dark"}
package main

import "fmt"

func main() {
    // Positive dividend: result is always positive
    fmt.Println(5 % 3)   // Output: 2
    fmt.Println(5 % -3)  // Output: 2

    // Negative dividend: result is always negative
    fmt.Println(-5 % 3)  // Output: -2
    fmt.Println(-5 % -3) // Output: -2
}
```

## Zero-Evaluation Rules

The `%` operator is subject to strict zero-evaluation rules for the right operand (the divisor). Go distinguishes between constant and non-constant divisors:

1. **Compile-Time Error:** If the divisor is a constant `0`, the compiler catches the error during compilation.
2. **Runtime Panic:** If the divisor is a variable that evaluates to `0` at runtime, the operation triggers a panic.

```go theme={"dark"}
package main

func main() {
    // Compile-time error:
    // invalid operation: 10 % 0 (division by zero)
    // _ = 10 % 0 

    a := 10
    b := 0
    
    // Compiles successfully, but triggers a runtime panic:
    // panic: runtime error: integer divide by zero
    _ = a % b 
}
```

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