Skip to content

Commit

Permalink
Merge pull request #66 from tsingbx/complex
Browse files Browse the repository at this point in the history
add doc for complex
  • Loading branch information
xushiwei authored Dec 14, 2023
2 parents d871020 + 31e0027 commit 828b9a3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions 109-Complex-Numbers/complex-1.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Initializing Complex Numbers
// There are two complex types in Go+. The complex64 and the complex128.
// Initializing complex numbers is really easy. You can use the constructor or the initialization syntax as well.

c1 := complex(10, 11) // constructor init
c2 := 10 + 11i // complex number init syntax
println c1, c2
7 changes: 7 additions & 0 deletions 109-Complex-Numbers/complex-2.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Parts of a Complex Number
// There are two parts of a complex number. The real and imaginary part. We use functions to get those.

cc := complex(23, 31)
realPart := real(cc) // gets real part
imagPart := imag(cc) // gets imaginary part
println realPart, imagPart
15 changes: 15 additions & 0 deletions 109-Complex-Numbers/complex-3.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Operations on a Complex Number
// A complex variable can do any operation like addition, subtraction, multiplication, and division.
//
// Let’s see an example to perform mathematical operations on the complex numbers.

c11 := complex(10, 11) // constructor init
c22 := 10 + 11i // complex number init syntax

ccc := complex(2, 3)
cc2 := 4 + 5i // complex initializer syntax a + ib
cc3 := c11 + c22 // addition just like other variables
println "Add: ", cc3 // prints "Add: (6+8i)"
re := real(cc3) // get real part
im := imag(cc3) // get imaginary part
println ccc, cc2, re, im // prints 6 8
1 change: 0 additions & 1 deletion 109-Complex-Numbers/complex.gop

This file was deleted.

0 comments on commit 828b9a3

Please sign in to comment.