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

# Swift Multiplication

The `*` operator in Swift is a binary arithmetic operator used to calculate the product of two operands. At the standard library level, it is primarily defined as a static method requirement within the `Numeric` protocol, though the language fully supports overloading it for asymmetric type combinations.

**Syntax**

```swift theme={"dark"}
let product = lhs * rhs
```

**Protocol Definition and Type Rules**
For types conforming to the `Numeric` protocol, the operator requires a symmetric signature where both operands and the return type are identical:

```swift theme={"dark"}
static func * (lhs: Self, rhs: Self) -> Self
```

Swift does not perform implicit type coercion between different numeric types (e.g., `Int` and `Double`). While the `Numeric` protocol enforces symmetry, the Swift language itself permits asymmetric operator overloading. The standard library utilizes this capability natively for types like `SIMD` vectors (allowing multiplication of a vector by a scalar), and developers can define custom asymmetric overloads for their own types.

**Overflow Behavior**
The behavior of the `*` operator when a product exceeds representable bounds depends on the underlying data type:

* **Integer Types:** Swift performs strict overflow checking. If the computed product exceeds the bounds of the integer type, Swift traps and triggers a runtime crash to prevent silent data corruption. For modulo arithmetic and wrap-around behavior, Swift provides the dedicated overflow multiplication operator (`&*`).
* **Floating-Point Types:** Types such as `Double` and `Float` follow the IEEE 754 standard. If a product exceeds the maximum representable finite value, the operator returns infinity (`inf` or `-inf`) without trapping or crashing.

**Precedence and Associativity**

* **Precedence Group:** `MultiplicationPrecedence`
* **Associativity:** Left
* **Evaluation Order:** Evaluated before operators in the `AdditionPrecedence` group (`+`, `-`). Multiple `*` operators in a single expression are evaluated from left to right.

**Operator Overloading**
The `*` operator can be overloaded for custom types by defining a `static func *`. It can be implemented symmetrically or asymmetrically, provided the function returns a valid instance of the declared return type.

```swift theme={"dark"}
struct CustomType {
    var value: Int
    
    // Symmetric overloading
    static func * (lhs: CustomType, rhs: CustomType) -> CustomType {
        return CustomType(value: lhs.value * rhs.value)
    }

    // Asymmetric overloading
    static func * (lhs: CustomType, rhs: Int) -> CustomType {
        return CustomType(value: lhs.value * rhs)
    }
}
```

**Compound Assignment**
The `*` operator serves as the foundation for the compound assignment operator `*=`, which multiplies the left-hand operand by the right-hand operand and assigns the result back to the left-hand operand. This requires the left-hand operand to be passed as an `inout` parameter (mutable via `var`).

```swift theme={"dark"}
static func *= (lhs: inout Self, rhs: Self)
```

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