-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from tsingbx/complex
add doc for complex
- Loading branch information
Showing
4 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.