In this lesson, you learn how to count in, but let's say I have a variable X and I will use X, lowercase
x has value of 10 and I have also a variable y.
We have a value to how much is X minus Y.
Someone could start with something like a cold or x minus donor white.
Unfortunately, this will just show 10 minus two here.
Only the variables have been replaced with the values, and that was all.
It doesn't work like this.
Mark, what can be made about it?
We can use an extra annotation that is responsible for counting its dollar, two opening brackets,
expression that should be evaluated and two closing brackets.
So now the result is correct.
What's interesting in this case, the donor designs can be removed.
The result remains correct.
What is much, much better?
We even don't need the additional spaces that normally in are mandatory.
But normally when calculating something, we usually want to save the result somewhere.
Luckily, that's easy enough to add variable name equals and ready.
When we take the variable to value, it is eight.
When using the syntax for calculations, we can do simultaneously more actions at one shot.
Look at this example.
First X will be divided by two.
So now X of value will be five.
Second Y will be doubled.
So now it's equal for next.
That will be assigned to value five minus four.
So it will be one.
And finally, you will have a value five times four.
So 20.
So we have here four expressions separated by comma.
Two new variables have been created, and the returned value is the value of the last expression from
the list.
If you don't believe we can check the values of the variables after all, five four one twenty.
The discuss here notation allows also for calculations in the style of language, C++ in C++, when
you want to increment a value of a variable, you can Type X Plus Plus.
Currently, X equals five.
After this, Operation X will be increased by one, so it will be equal.
Six.
Why was then five this great?
That's because I said after these Operation X will be increased.
That means that first we have displayed the value of X and the value was still five, and later we increased
the value to six.
So when I execute the command to once again, I will see six, but X should have a value of seven.
Once again, I see seven, but the value of X is now eight.
So when I test the X value by displaying it, I can see that the value is indeed eight.
Let's remind that the Y has the value of four.
So the X bigger than Y.
The value one was returned, and it reflects a logical value of true and is it true that X is lower
than Y?
The result is zero so false?
And is it true that X is equal Y?
No, true.
And is it true that X is equal x?
So this type of notation allows us to do some mathematical calculations, but also perform simple,
logical expressions.
Some trouble may be observed, especially when dividing the numbers, because all the calculations are
done here on integers 20 divided by five is four, 20 divided by 10 is two, but 20 divided by 15 is
only one.
20 divided by 11 is still only one.
But if a mathematical around operation would be used, it should be rather two.
So the calculations here are pure integer operations for a scientist that could be a problem.
But for this, I mean, I suppose that's not a huge issue.
So try to remember dollar and double opening and closing brackets with the variables and arithmetic
operations inside.
That's the recommended way of performing calculations in Bath.
However, if you would need to read the existing older script, develop some time ago by someone else.
You may still see other ways of calculating mathematical expressions.
That's why we will now learn a command.
Exp.
We've asked.
You can again pass as arguments, variables or a string containing text that could be interpreted as
a numeric value with a limited set of arithmetic operators.
Now we used X and Y, and the result of adding those two values is 12.
If you used to work on a constant value, no problem.
Just type the new constant value X plus one equals nine.
Let's check if it's still possible to delete the donor resign in front of X.
No.
Is it possible to remove the additional spaces around the class design?
No.
That means that Exp requires a very strict syntax.
Let us continue our experiments.
Can we subtract?
No problem.
Eight minus four equals four, right?
Can we divide x divided by two?
That's good.
So surely we can multiply as well.
X Multiply it by Y and I know, and that's quite stupid error because there is a problem with comments
d, but we didn't put anything like that in the comments.
What's going on?
Well, where if we list the current directory, then indeed there is a common fixed file here.
But what has it in common with them?
Multiply operation?
Hmm.
Multiply symbol is asterisk, and asterisk is a metric.
They're matching all files and subdirectories.
So the comment that the expert was supposed to execute was eight the value of X.
Next, the names of all five from the current directory and finally, for the value of Y operation like
that needed to fail to correct the situation, we should proceed the asterisk with a backslash, which
will quote the asterisk so X will see indeed asterisk as a symbol, pointing to multiply operation.
So that is how we can use this for basic arithmetic operations.
We've exp know how the result of that operation can be saved in a variable.
If you wish to save the result of the EXP calculation in that variable Type Z equals $ and in the brackets
put the expression that should be evaluated.
It works, but the syntax is not so nice, as in the previous examples due to long line looks and buffer
history.
Let me present one more way of getting results of a comment instead of dollar and brackets.
Sometimes a reverse apostrophe is used on most keyboards.
The reverse apostrophe is on the same button as the tilde, and Julia is usually under escape.
That is working correctly, but the reverse apostrophe small.
Someone could read it as an apostrophe and the other would think that it's just a missed on the screen.
So we have seen two methods of doing math in.
But are there more?
Yes, there is, for example, a dedicated program named B.S. less or more.
It's a kind of scientific calculator.
You enter some quite intuitive expressions and the B C should display the result.
A is two hundred B is 100.
C should be a minus three times B.
So what value has C?
It's minus hundred.
Of course, we are here more interested in using a calculator in, but from what we don't want interactively
enter expressions and check the results.
So for us, it would be better somehow to pass arguments to B C so that B C will be able to perform
some calculations and will return a result that could be stored in another variable.
How to do it For this, we need to stand to receive a pipe, a text.
The text should contain the expression that B.C. is going to interpret as mathematical expression in
our case.
Echo output text eight plus four b c gets this text on standard input and.
The result 12.
If you would like to save the result in a variable again, you already know what should be done.
Use the dollar and brackets and tax the same trick as just for a moment with the.
It works, but wouldn't the dollar weave double brackets be easier?
Surely.
But at least we know now pre methods for calculating value of mathematical expressions.
Would you be interested to more on this topic?
Because there are more methods we have like we have declared, but I think that it would be enough for
now.
Someone could wonder why we have so many methods for doing the same thing in the show wouldn't just
one good method to be better instead of multiple ways of adding values.
I think that the reason of that status is, again, history buff and more generally show so we're supposed
to be used by system administrators.
These operations managing processes devices should be the essential activities done by admin.
The calculations are more business application specific.
So at the very beginning, the calculation in Bosch was not so important, with time different outdoors
developed solutions for performing basic calculations.
One used Exp.
The other b c.
Finally, the dollar and the double bracket meant that it was made available.
Now we are at this point in the history where you can select the method that you like the most.
The choice is yours.
This lesson was dedicated to calculations in math in the next lesson, and we will work with three CEOs
don't.