+ 2

Question

Hello everyone, I'm a new learner here, I want to ask some question, I still don't understand very well about this math calculation. Can anyone explain this? Math.abs(Math.min(-6, 3)); Math.abs(-6,3); // 6,3 so the min = 3 Math.min(-6,3); // -6,3 so the min = -6 Math.abs(Math.min(-6, 3)); // why this equal 6 ? not 3 ?

10th Feb 2018, 4:00 AM
Sambath R. Oudom
Sambath R. Oudom - avatar
5 Answers
+ 7
Well, the reason it doesn't equal 3 is because you just have the order of the math wrong. What the program does is evaluate any expression within the inner most parentheses first, then moves its way outwards. In this case, the program first evaluates what the lowest value is out of the two options (-6 and 3), which returns -6. From there, it finds the absolute value of the result of the previous calculation, resulting in 6. Hope this helped!
10th Feb 2018, 4:16 AM
Faisal
Faisal - avatar
+ 16
first find min. of -6,3 & then take the absolute value of the result //Math.abs (-6); = 6
10th Feb 2018, 5:27 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
Thank you very much, now I can understand it clearly.
10th Feb 2018, 9:52 AM
Sambath R. Oudom
Sambath R. Oudom - avatar
0
because it -6 not 6
10th Feb 2018, 12:55 PM
Mahmoud Ragab Mohamed Ahmed
Mahmoud Ragab Mohamed Ahmed - avatar
0
First it checked minimum. example , min(7,-9),so min=-9 secondly checked absolute . example, abs(-9). this is not the answer. it will be 9. because abs(-9)=[-9]=9.
14th Dec 2018, 4:23 PM
Likhon
Likhon - avatar