Skip to content

Commit 828b9a3

Browse files
authored
Merge pull request #66 from tsingbx/complex
add doc for complex
2 parents d871020 + 31e0027 commit 828b9a3

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

109-Complex-Numbers/complex-1.gop

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Initializing Complex Numbers
2+
// There are two complex types in Go+. The complex64 and the complex128.
3+
// Initializing complex numbers is really easy. You can use the constructor or the initialization syntax as well.
4+
5+
c1 := complex(10, 11) // constructor init
6+
c2 := 10 + 11i // complex number init syntax
7+
println c1, c2

109-Complex-Numbers/complex-2.gop

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Parts of a Complex Number
2+
// There are two parts of a complex number. The real and imaginary part. We use functions to get those.
3+
4+
cc := complex(23, 31)
5+
realPart := real(cc) // gets real part
6+
imagPart := imag(cc) // gets imaginary part
7+
println realPart, imagPart

109-Complex-Numbers/complex-3.gop

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Operations on a Complex Number
2+
// A complex variable can do any operation like addition, subtraction, multiplication, and division.
3+
//
4+
// Let’s see an example to perform mathematical operations on the complex numbers.
5+
6+
c11 := complex(10, 11) // constructor init
7+
c22 := 10 + 11i // complex number init syntax
8+
9+
ccc := complex(2, 3)
10+
cc2 := 4 + 5i // complex initializer syntax a + ib
11+
cc3 := c11 + c22 // addition just like other variables
12+
println "Add: ", cc3 // prints "Add: (6+8i)"
13+
re := real(cc3) // get real part
14+
im := imag(cc3) // get imaginary part
15+
println ccc, cc2, re, im // prints 6 8

109-Complex-Numbers/complex.gop

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)