Logo

Programming-Idioms

History of Idiom 77 > diff from v9 to v10

Edit summary for version 10 by :

Version 9

2015-09-30, 11:48:25

Version 10

2015-10-29, 14:05:16

Idiom #77 Complex number

Declare a complex x and initialize it with value (3i - 2). Then multiply it by i.

Idiom #77 Complex number

Declare a complex x and initialize it with value (3i - 2). Then multiply it by i.

Imports
use Math::Complex;
Imports
use Math::Complex;
Code
my $x = 3*i - 2;
$x *= i;
Code
my $x = 3*i - 2;
$x *= i;
Comments bubble
Simple version: clear, but not efficient. It starts with i, then uses a multiplication and a subtraction to build the complex number.
Comments bubble
Simple version: clear, but not efficient. It starts with i, then uses a multiplication and a subtraction to build the complex number.
Code
x := 3i - 2
x *= 1i
Code
x := 3i - 2
x *= 1i
Comments bubble
complex128 is a built-in type.

1i denotes the imaginary unit i.
Comments bubble
complex128 is a built-in type.

1i denotes the imaginary unit i.
Doc URL
https://golang.org/ref/spec#Numeric_types
Doc URL
https://golang.org/ref/spec#Numeric_types
Demo URL
http://play.golang.org/p/aWVjAibhJZ
Demo URL
http://play.golang.org/p/aWVjAibhJZ