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

`complex128` is a built-in numeric type in Go that represents a complex number using 128 bits of memory. It is composed of two 64-bit IEEE 754 floating-point numbers (`float64`): one representing the real component and the other representing the imaginary component.

## Memory Layout and Precision

* **Total Size:** 16 bytes (128 bits).
* **Real Part:** 8 bytes (`float64`).
* **Imaginary Part:** 8 bytes (`float64`).
* **Zero Value:** `0 + 0i` (or simply `0`).

## Declaration and Initialization

You can initialize a `complex128` variable using either the built-in `complex()` function or the imaginary literal suffix `i`.

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

import "fmt"

func main() {
    // Method 1: Using the built-in complex() function
    // Signature: func complex(r, i FloatType) ComplexType
    var a complex128 = complex(5.5, 3.2)

    // Method 2: Using literal syntax with the 'i' suffix
    var b complex128 = 5.5 + 3.2i

    // Method 3: Type inference (Go defaults to complex128 for complex literals)
    c := 5.5 + 3.2i

    fmt.Printf("a: %v\n", a)
    fmt.Printf("b: %v\n", b)
    fmt.Printf("Type: %T, Value: %v\n", c, c) 
    // Output: Type: complex128, Value: (5.5+3.2i)
}
```

## Component Extraction

Go provides built-in functions to extract the real and imaginary `float64` components from a `complex128` value.

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

import "fmt"

func main() {
    c := 7.1 + 4.9i

    // Extract the real part
    // Signature: func real(c ComplexType) FloatType
    r := real(c) // Type: float64, Value: 7.1

    // Extract the imaginary part
    // Signature: func imag(c ComplexType) FloatType
    i := imag(c) // Type: float64, Value: 4.9

    fmt.Printf("Real: %f, Imaginary: %f\n", r, i)
}
```

## Arithmetic Operations

`complex128` supports standard arithmetic operators. Operations are performed on both the real and imaginary planes according to standard complex arithmetic rules.

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

import "fmt"

func main() {
    c1 := 2.0 + 3.0i
    c2 := 1.0 + 2.0i

    add := c1 + c2 // (3.0+5.0i)
    sub := c1 - c2 // (1.0+1.0i)
    mul := c1 * c2 // (-4.0+7.0i)
    div := c1 / c2 // (1.6-0.2i)

    fmt.Printf("Addition: %v\n", add)
    fmt.Printf("Subtraction: %v\n", sub)
    fmt.Printf("Multiplication: %v\n", mul)
    fmt.Printf("Division: %v\n", div)
}
```

## The `math/cmplx` Package

For advanced mathematical operations, Go provides the `math/cmplx` standard library package. This package is specifically designed to operate exclusively on `complex128` values (it does not support `complex64`).

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

import (
    "fmt"
    "math/cmplx"
)

func main() {
    c := 2.0 + 3.0i
    
    // Returns the modulus/magnitude (float64)
    abs := cmplx.Abs(c)   
    
    // Returns the complex conjugate (complex128)
    conj := cmplx.Conj(c) 
    
    // Returns the phase/argument (float64)
    phase := cmplx.Phase(c) 

    fmt.Printf("Absolute value: %f\n", abs)
    fmt.Printf("Conjugate: %v\n", conj)
    fmt.Printf("Phase: %f\n", phase)
}
```

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