Go defines two numeric types for complex numbers, complex64
and complex128
. This is rare. Most programming languages define complex numbers as the combination of a real and complex part, rather than including a specific primitive for the purpose. (Even in group theory complex numbers are formally constructed as pairs of reals.) Why did the designers of Go decide that Go needed primitive types for complex numbers?
A complex number is a basic data type of GoLang. It is a combination of the real and imaginary part, where both parts of the complex number will be float type in the go program. Complex numbers are further categorized into two parts in go language.
The ComplexType type in Golang documentation is a placeholder for two complex number data types: complex64. complex128.
The type complex128 in Golang is the set of all complex numbers with float64 real and imaginary parts. Complex numbers consist of a real and an imaginary part, as illustrated below: Real and Imaginary Parts of a Complex Number. To create a complex128 number in Golang, you can use the in-built complex function.
Ken Thompson, one of the principal Go authors, wanted complex numbers in Go and so he added them to the Go language specification and implemented complex numbers for the Go gc compilers.
Because they are dead useful? And: Go complex numbers are just that: A real and imaginary part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With