Hello and welcome to Golang programming language course.
In the previous session, we talked about floating point numbers and in decision, we want to talk about
the others detail types concept.
Complex numbers.
Complex numbers are one of the basic types, and Go Link Go has two complex types of different sizes
Complex 64 and Complex 128.
Phil, 32, and Philip, 64, are also part of these complex numbers, the inbuilt function creates
the complex number from its imaginary and real part and inbuilt imaginary and real function extract
those parts.
Complex 64 complex numbers, which contains four lottery tool as a real and imaginary component, complex,
one hundred and twenty eight.
Complex numbers which contain slots 64 as the real and imaginary component.
The default type for a complex number and go lang is complex one hundred and twenty eight.
Now, let's go to this court get program and illustrate how to use of complex numbers.
First, define two variables like that a equals two point thirty five and life B equals three point
seventy six.
Go also provides a built in function named complex for creating complex numbers.
If you're creating a complex number with the variables instead of literals, then you will need to use
the complex function.
So we create a complex number by complex function.
Now we define the variable like Bash C and initialize it by complex function complex and set A and B
as arguments for dysfunction.
Now display value and type of C variable FP C and f f tied o c colin person t uppercase and set c variable
b format.
The court saved the project and execute the program.
Go run thought backslash mean that goal?
Now we can see the output, the value is two point thirty five plus three point seventy six I.
And Type of civil liberties complex.
One hundred and twenty eight.
Not death.
Both real and imaginary parts of the complex number must be of the same floating point type.
If you try to create a complex number with different real and animation types, then the compiler will
turn it off.
So we do another sample first.
Clear the last code.
And defined two variables by two types.
For example, via a float theory to initialize it by four point ninety two and define another variable
like that, be by the time floats 64 and initialize it by the value, for example, seven point thirty
eight and now go to the next line and define another variable like that C equals and create a complex
number bunkering complex function complex and set A and B as arguments for each day and B.
OK.
We have a rule the following his statement won't campaign, both real and imaginary paws must be of
the same floating point type here as fellow Terry Toole and BS followed 64.
And it won't comply, and it has compiled at all.
OK, you can perform arithmetic operations like addition, subtraction, multiplication and division
and complex number.
So first, clear the last code.
So define a variable like that.
A equals three plus five.
And define another variable like that.
E equals two plus three i.
Now define another variable life result, one for addition to variables A and B together, that result
one equals a plus B.
And go to the next line and define another variable like valve resolve to force contraction between
A and B B minus A.
And go to the next line, define another variable valve result three equals a multiplication B and another
variable like that result four equals a Division B.
Now go to next line and display the results value if P
resolved one, resolved two, resolved three and resolved for reformat the call, save the project and
execute the program.
Now run the comment.
Go from dot back.
This mean that go.
Now we can see the output and we could perform arithmetic operations on complex numbers in order not
to prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.