Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are complex numbers a primitive numeric type in Go?

Tags:

go

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?

like image 458
Matthew Piziak Avatar asked Mar 03 '14 00:03

Matthew Piziak


People also ask

Why does Golang have 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.

What is complex type Golang?

The ComplexType type in Golang documentation is a placeholder for two complex number data types: complex64. complex128.

What is 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.


2 Answers

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.

like image 98
peterSO Avatar answered Sep 28 '22 04:09

peterSO


Because they are dead useful? And: Go complex numbers are just that: A real and imaginary part.

like image 35
Volker Avatar answered Sep 28 '22 02:09

Volker