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

# Kotlin Division

The `/` operator in Kotlin is the arithmetic division operator, used to evaluate the quotient of two operands. At compile time, Kotlin translates the `/` operator into a method invocation of the `div()` member or extension function via operator overloading conventions.

```kotlin theme={"dark"}
val result = a / b
// Translates internally to:
val result = a.div(b)
```

## Primitive Type Behavior

**Signed and Unsigned Integer Division**
When both the dividend and the divisor are integer types (signed: `Byte`, `Short`, `Int`, `Long`; unsigned: `UByte`, `UShort`, `UInt`, `ULong`), the `/` operator performs integer division. Arithmetic operations on smaller types (`Byte`, `Short`, `UByte`, `UShort`) implicitly promote the operands to `Int` or `UInt` respectively. The return type resolves to the 64-bit variant (`Long` or `ULong`) only if at least one operand is 64-bit; otherwise, it resolves to the 32-bit variant (`Int` or `UInt`).

Evaluation truncates towards zero, strictly discarding any fractional component. Unsigned types utilize unsigned arithmetic instructions, yielding different results than signed division for bit-equivalent values.

```kotlin theme={"dark"}
val a: Byte = 5
val b: Byte = 2
val c = a / b // Evaluates to 2, type is Int

val u1: UInt = 5u
val u2: UInt = 2u
val u3 = u1 / u2 // Evaluates to 2u, type is UInt
```

**Floating-Point Division**
If at least one operand is a floating-point type (`Float` or `Double`), the `/` operator performs floating-point division. The return type is implicitly promoted to the widest floating-point type present in the expression.

```kotlin theme={"dark"}
val a: Int = 5
val b: Double = 2.0
val c = a / b // Evaluates to 2.5, type is Double
```

## Division by Zero Mechanics

The behavior of the `/` operator when the divisor evaluates to zero depends strictly on the operand types and the compilation target:

* **Integer Types (JVM):** Throws an `ArithmeticException` at runtime for both signed and unsigned integer division.
* **Integer Types (Kotlin/Native):** Triggers a hardware trap or crash (e.g., `SIGFPE` / `EXC_ARITHMETIC`). For performance reasons, Kotlin/Native does not inject zero-checks into integer division operations, meaning it does not throw a catchable Kotlin exception.
* **32-bit and Smaller Integer Types (Kotlin/JS):** Does *not* throw an exception. Because Kotlin/JS maps 32-bit and smaller integers (`Int`, `Short`, `Byte`) to JavaScript's `Number` type (IEEE 754 floats) and emulates integer division using bitwise operations (e.g., `(a / b) | 0`), dividing a non-zero `Int` by `0` evaluates to `0` (since `Infinity | 0` evaluates to `0`).
* **64-bit Integer Types (Kotlin/JS):** Throws an `ArithmeticException`. In Kotlin/JS, 64-bit integers (`Long` and `ULong`) are not mapped to standard JavaScript numbers. They are emulated (or utilize `BigInt`), and their division implementation explicitly checks for zero.
* **Floating-Point Types (All Targets):** Adheres to the IEEE 754 standard and does not throw an exception. Instead, it evaluates to `Infinity` (e.g., `1.0 / 0.0`), `-Infinity` (e.g., `-1.0 / 0.0`), or `NaN` (Not a Number, e.g., `0.0 / 0.0`).

## Operator Overloading

The `/` operator can be implemented for user-defined types by declaring a function named `div` with the `operator` modifier. The function signature is highly flexible; the parameter type (divisor) and the return type (quotient) do not need to match the receiver type (dividend), allowing for asymmetric division operations.

```kotlin theme={"dark"}
class Vector(val x: Double, val y: Double) {
    // Overloading the '/' operator for Vector / Double
    operator fun div(scalar: Double): Vector {
        return Vector(x / scalar, y / scalar)
    }
}

val v1 = Vector(4.0, 8.0)
val v2 = v1 / 2.0 // Resolves to v1.div(2.0)
```

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