Skip to main content
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.

Component Extraction

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

Arithmetic Operations

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

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).
Tired of Poor Go Skills? Fix That With Deep Grasping!Learn More