# Go: panic: runtime error: integer divide by zero

**Code:** `panic: runtime error: integer divide by zero` · **Category:** Go · **Seen on:** Go

Integer division or modulo by zero.

## Meaning

Floating-point division by zero yields Inf/NaN, but integer division panics. Validate the divisor, especially values from user input, lengths, or counters (`total / count`).

## Common causes

- Divisor derived from len() of an empty slice
- User input zero
- Counter not incremented
- Uninitialised struct field used as divisor
- Modulo by zero

## Quick fix

1. Check `if d == 0 { return error }`
2. Use float division if Inf is acceptable
3. Validate input at boundaries

## Detailed fix by platform

### Go

1. `if count == 0 { return 0, errors.New("empty") }; avg := sum / count`

## How to diagnose

1. **Divisor** — Zero when?
2. **Source** — Input or length?
3. **Guard** — Missing?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/integer-divide-by-zero)
