1 00:00:00,240 --> 00:00:01,200 ‫Welcome back. 2 00:00:01,200 --> 00:00:04,050 ‫And this video, we are going to cover math. 3 00:00:04,050 --> 00:00:06,720 ‫So the math class pretty much. 4 00:00:06,750 --> 00:00:10,410 ‫Not just math, the subject in school, but the math class. 5 00:00:10,410 --> 00:00:22,050 ‫And therefore and therefore, I created a new project here and I'm going to console right line in here 6 00:00:22,050 --> 00:00:24,240 ‫to keep the program program open. 7 00:00:24,240 --> 00:00:31,140 ‫You can alternatively always start with control f five if you want to keep the console open without 8 00:00:31,140 --> 00:00:33,480 ‫this console read line line. 9 00:00:33,480 --> 00:00:36,150 ‫But anyways, let's go ahead and use math. 10 00:00:36,150 --> 00:00:39,750 ‫In order to use math, we need to do the following. 11 00:00:39,750 --> 00:00:42,780 ‫We need to simply type in math. 12 00:00:42,780 --> 00:00:49,050 ‫And then you can see there is system dot math, a class which provides constants and static methods 13 00:00:49,050 --> 00:00:54,510 ‫for tried economic, logarithmic and other common mathematical functions. 14 00:00:54,510 --> 00:00:57,930 ‫So you don't need to do loads of the stuff on your own. 15 00:00:58,140 --> 00:01:00,870 ‫You don't need to write methods for many things. 16 00:01:00,870 --> 00:01:02,130 ‫They are there already. 17 00:01:02,130 --> 00:01:05,850 ‫So whenever you want, for example, to seal something. 18 00:01:06,060 --> 00:01:09,120 ‫So if you want to round up, you can do the following. 19 00:01:09,120 --> 00:01:19,410 ‫You can just say ceiling and I'm going to use math dot ceiling and then you simply need to enter the 20 00:01:19,410 --> 00:01:19,950 ‫decimal. 21 00:01:19,950 --> 00:01:25,710 ‫So let's say I want to seal 15.3, then that's how I do it. 22 00:01:25,710 --> 00:01:31,710 ‫So let's see what the result is and we'll see ceiling 16. 23 00:01:31,710 --> 00:01:39,540 ‫So even if 15.3 usually wouldn't be sealed because it's below 0.5, it still is being sealed here. 24 00:01:39,540 --> 00:01:41,640 ‫So that's how you can round up a value. 25 00:01:42,150 --> 00:01:42,450 ‫All right. 26 00:01:42,450 --> 00:01:46,500 ‫You get the next full number with the ceiling method. 27 00:01:46,500 --> 00:01:49,200 ‫So this math class has a method called ceiling. 28 00:01:49,200 --> 00:01:56,010 ‫But in general, if you enter math, you can see there are plenty of methods, there are constants and 29 00:01:56,010 --> 00:01:56,460 ‫methods. 30 00:01:56,460 --> 00:02:00,840 ‫So you can get the sinner's or sinus you can get. 31 00:02:01,730 --> 00:02:05,360 ‫Exponentials, maximum minimum values and so forth. 32 00:02:05,360 --> 00:02:08,570 ‫And then you see here the constants are E and PI. 33 00:02:08,570 --> 00:02:14,030 ‫So those two constants are available and those are the different methods that we have. 34 00:02:14,030 --> 00:02:16,730 ‫So let's look at some other methods. 35 00:02:17,480 --> 00:02:20,390 ‫Let's look at floor. 36 00:02:20,390 --> 00:02:27,350 ‫So round down or floor or something and that's done with math dot flor. 37 00:02:28,820 --> 00:02:33,560 ‫And if we flor 15.3 again, this time we get 15. 38 00:02:33,560 --> 00:02:38,510 ‫So we get the next lower full number or whole number. 39 00:02:38,510 --> 00:02:40,580 ‫So 15 is a whole number. 40 00:02:40,880 --> 00:02:44,270 ‫Then we have some other ones. 41 00:02:44,270 --> 00:02:46,730 ‫Let's say I want to get the lower of two values. 42 00:02:46,730 --> 00:02:53,990 ‫So I have two values, let's say number one, which is 13 and number two, which is nine. 43 00:02:53,990 --> 00:02:57,290 ‫Now I would like to get the lower of the two here. 44 00:02:57,290 --> 00:02:58,880 ‫It's easier and obvious. 45 00:02:58,880 --> 00:03:01,100 ‫We can see, okay, nine is lower than 13. 46 00:03:01,100 --> 00:03:02,900 ‫We don't need the method for that. 47 00:03:02,900 --> 00:03:10,250 ‫But if the input is something else, so if the user can do the input or if it's from a database or something 48 00:03:10,250 --> 00:03:16,460 ‫like that, then this method could be useful because we always will get the lower of the two values. 49 00:03:16,790 --> 00:03:25,460 ‫So let's say lower of num one which is this. 50 00:03:27,310 --> 00:03:33,910 ‫And number two, which is that is and that's this. 51 00:03:33,910 --> 00:03:37,480 ‫So what is it, number one num two. 52 00:03:37,480 --> 00:03:41,350 ‫And finally we use math dot min. 53 00:03:42,100 --> 00:03:47,740 ‫So there is this method called min returns the smaller of two eight bit unsigned integers. 54 00:03:47,740 --> 00:03:55,090 ‫So here it only accepts integers and here I say num one and num two because these are the two variables 55 00:03:55,090 --> 00:03:56,140 ‫that I'm looking at. 56 00:03:57,070 --> 00:03:57,400 ‫All right. 57 00:03:57,400 --> 00:03:59,170 ‫Now, what will it return? 58 00:03:59,170 --> 00:04:02,170 ‫Well, you guessed it, it will return nine. 59 00:04:02,170 --> 00:04:07,600 ‫So it says lower of nine, one is 13 and num two, nine is nine. 60 00:04:09,100 --> 00:04:11,860 ‫Now, you can do the opposite of course for the higher value. 61 00:04:12,220 --> 00:04:17,890 ‫So see w higher of num one 62 00:04:20,650 --> 00:04:35,140 ‫and number two is num one num two math and now we use the max method num one num two and that's it. 63 00:04:35,410 --> 00:04:36,880 ‫So now let's check it out. 64 00:04:36,880 --> 00:04:38,560 ‫This time we should get 13. 65 00:04:39,250 --> 00:04:44,680 ‫So the higher of 13 and num 129 is 13. 66 00:04:45,070 --> 00:04:46,090 ‫All right, that's good. 67 00:04:46,990 --> 00:04:50,380 ‫But there are some more things like by the power. 68 00:04:50,380 --> 00:05:01,180 ‫So for example, three, two, the power of five is and what is it. 69 00:05:01,180 --> 00:05:03,130 ‫It's math dot pow. 70 00:05:06,040 --> 00:05:09,880 ‫So the power method returns a specified number. 71 00:05:09,880 --> 00:05:11,800 ‫Race to the specified power. 72 00:05:12,340 --> 00:05:16,720 ‫So three to the power of five, three and five. 73 00:05:18,990 --> 00:05:19,350 ‫Now. 74 00:05:19,350 --> 00:05:20,430 ‫Let's check it out. 75 00:05:22,850 --> 00:05:25,850 ‫And we are we get 243. 76 00:05:28,730 --> 00:05:34,400 ‫Then if you just want to use pie, which is very common, pie is 77 00:05:37,670 --> 00:05:42,290 ‫and math pie like that. 78 00:05:43,040 --> 00:05:44,210 ‫So that's what pie is. 79 00:05:44,210 --> 00:05:46,520 ‫And you will see the precision as well. 80 00:05:46,700 --> 00:05:52,850 ‫So there is, of course, only a specific precision, and that's the precision of a of a double. 81 00:05:53,060 --> 00:06:00,640 ‫So I can see it's one, two, three, six, nine, 12 and 11. 82 00:06:00,650 --> 00:06:03,350 ‫So it's 12 digits here in total. 83 00:06:05,330 --> 00:06:20,390 ‫Then if you want to have the square root, the square root of 25 is and then you use the math as Q are 84 00:06:20,390 --> 00:06:22,180 ‫DT method. 85 00:06:22,190 --> 00:06:26,200 ‫So sqrt gives you the square root of a double value. 86 00:06:26,210 --> 00:06:30,290 ‫So it doesn't have to be a whole number, it can be a double value. 87 00:06:30,560 --> 00:06:33,680 ‫So in my case, it's an integer with the value of 25. 88 00:06:33,680 --> 00:06:36,500 ‫So the square root of 25 is five. 89 00:06:39,290 --> 00:06:44,180 ‫Then if you want to have the absolute number, which means it's always going to be positive no matter 90 00:06:44,180 --> 00:06:44,750 ‫what. 91 00:06:44,840 --> 00:06:56,990 ‫Then you use the ABS method, so CW always positive is and then you enter math dot abs. 92 00:06:57,560 --> 00:07:05,480 ‫So returns the absolute value of a decimal number, a number that is greater than or equal to decimal 93 00:07:05,900 --> 00:07:09,650 ‫value, but less than or equal to decimal max value. 94 00:07:09,650 --> 00:07:13,490 ‫So we can use pretty much the whole decimal range. 95 00:07:13,610 --> 00:07:23,570 ‫And here if I enter something like -25, then that will return 25 because it's always positive. 96 00:07:23,570 --> 00:07:25,640 ‫So always positive is 25. 97 00:07:27,970 --> 00:07:28,750 ‫Next. 98 00:07:29,950 --> 00:07:33,390 ‫There is one more thing that I want to show you and that's using coziness. 99 00:07:33,400 --> 00:07:46,710 ‫So CW codes of one is and that's math dot co's and here you can enter a double. 100 00:07:46,720 --> 00:07:48,190 ‫I'm just going to enter one. 101 00:07:48,850 --> 00:07:57,700 ‫Let's check it out that we are coding of inverse of one is 0.5, four and so forth. 102 00:08:01,230 --> 00:08:04,860 ‫Of course, there are many more methods and I'm not going to cover all of them, of course. 103 00:08:04,860 --> 00:08:07,160 ‫But you can simply check them out. 104 00:08:07,170 --> 00:08:15,150 ‫You can see you can use the logarithm, then exponent or exponential and so forth. 105 00:08:15,150 --> 00:08:22,740 ‫So there's plenty even coziness, hyperbolic costs or hyperbolic costs, a sinus, a coziness and so 106 00:08:22,740 --> 00:08:22,980 ‫forth. 107 00:08:22,980 --> 00:08:29,910 ‫So there's plenty of cool methods and whenever you work with maths, just consider using the math class 108 00:08:29,910 --> 00:08:32,100 ‫because well, it might help you out. 109 00:08:32,430 --> 00:08:32,910 ‫All right. 110 00:08:32,910 --> 00:08:34,710 ‫So see you in the next video.