Welcome back.
In this video we will cover the math class, not math as like the school subject, but the class responsible
for math operations in C sharp.
All right.
So let's start.
And therefore I created a new project here.
And I'm gonna console read line in here to keep the program program open.
You can alternatively always start with control F5 if you want to keep the console open without this
console redline line.
But anyways, let's go ahead and use math.
In order to use math, we need to do the following.
We need to simply type in math and then you can see there is system dot math, a class which provides
constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
So you don't need to do loads of the stuff on your own.
You don't need to write methods for many things, they are there already.
So whenever you want for example, to seal something.
So if you want to round up you can do the following.
You can just say ceiling.
And I'm going to use math dot ceiling.
And then you simply need to enter the decimal.
So let's say I want to seal 15.3.
Then that's how I do it.
So let's see what the result is and we'll see.
Ceiling 16.
So even if 15.3 usually wouldn't be sealed because it's below 0.5, it still is being sealed here.
So that's how you can round up a value.
All right.
You get the next full number with the sealing method.
So this math class has a method called sealing.
But in general if you enter math you can see there are plenty of methods.
There are constants and methods.
So you can get the sinus or sinus.
You can get exponentials maximum minimum values and so forth.
And then you see here the constants are e and pi.
So those two constants are available.
And those are the different methods that we have.
So let's look at some other methods.
Let's look at floor.
So round down or floor something.
And that's done with math dot floor.
And if we floor 15.3 again this time we get 15.
So we get the next lower full number or whole number.
So 15 is a whole number.
Then we have some other ones.
Let's say I want to get the lower of two values.
So I have two values.
Let's say number one which is 13 and number two which is nine.
Now I would like to get the lower of the two here.
It's easier and obvious.
We can see okay nine is lower than 13.
We don't need a method for that.
But if the input is something else.
So if the user can do the input or if it's from a database or something like that, then this method
could be useful because we always will get the lower of the two values.
So let's say lower of num one which is this, and num two which is, that is and that's this.
So what is it, number one.
Number two.
And finally we use math dot min.
So there is this method called min returns the smaller of two eight bit unsigned integers.
So here it only accepts integers.
And here I say num1 and num2 because these are the two variables that I'm looking at all right.
Now what will it return?
Well, you guessed it, it will return nine.
So it says lower of num one is 13 and num two nine is nine.
Now you can do the opposite of course for the higher value.
So CW higher of num1 and num2 is num one num two math.
And now we use the max method num1 and Num2.
And that's it.
So now let's check it out.
This time we should get 13.
So the higher of 13 and num 129 is 13.
All right that's good.
But there are some more things like by the power.
So for example three two the power of five is and what is it?
It's math dot pow.
So the POW method returns a specified number raised to the specified power.
So three to the power of five, three and five.
Now let's check it out.
And there we are.
We get 243.
Then if you just want to use pi, which is very common, Pi is and math dot pi like that.
So that's what pi is.
And you will see the precision as well.
So there is of course only a specific precision.
And that's the precision of a of a double.
So as you can see it's one, two, three, six, nine, 12 and 11.
So it's 12 digits here in total.
Then if you want to have the square root the square root of 25 is.
And then you use the math sqrt method.
So sqrt gives you the square root of a double value.
so it doesn't have to be a whole number.
It can be a double value.
So in my case it's an integer with the value of 25.
So the square root of 25 is five.
Then if you want to have the absolute number which means it's always going to be positive no matter
what, then you use the apps method.
So CW always positive is And then you enter math dot abs.
So returns the absolute value of a decimal number, a number that is greater than or equal to decimal
min value, but less than or equal to decimal max value.
So we can use pretty much the whole decimal range.
And in here if I enter something like -25 then that will return 25 because it's always positive.
So always positive is 25.
Next there is one more thing that I want to show you and that's using coziness.
So CW cos of one is and that's math dot cos and here you can enter a double.
I'm just going to enter one.
Let's check it out.
There.
We are coding of this of one is 0.54 and so forth.
Of course there are many more methods and I'm not going to cover all of them of course.
But here you can simply check them out.
You can see you can use the logarithm then exponent or exponential and so forth.
So there's plenty even coziness hyperbolicus or hyperbolicus, a sinus, a coziness and so forth.
So there's plenty of cool methods.
And whenever you work with maths, just consider using the math class because, well, it might help
you out.
All right.
So see you in the next video.
All right.
I hope that made some sense to you.
That should be enough to get you started on the math class.
So then let's move on to the next video.
See you there.