0

I was just doing a simple maths operation:

$s = 158 + 46 \times -1: \Rightarrow s = 112$

and

$s = (158 + 46) \times -1:\Rightarrow s = -204$

In the latter case $158 + 48$ gets calculated first and then multiplied by $-1$, but in the former case I.E.

$s = 158 + 46 \times -1:\Rightarrow s = 112$

Why the result $112$ ?

Chiranjeev_Kumar
  • 3,061
  • 16
  • 30

2 Answers2

3

158 + 46 * -1 is interpreted as 158 + (46 * (-1)) since multiplication precedes addition and the minus sign precedes multiplication and addition. See Order of operations.

J.-E. Pin
  • 40,163
  • Thanks alot for your answer , i am a js programmer , was just looking up the JS doc's and came across the operator precedence documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence , that helped me understand what i was missing too . Thanks alot though ! – Alexander Solonik Aug 15 '15 at 19:52
  • You're welcome. – J.-E. Pin Aug 15 '15 at 20:16
1

BODMAS Rule:-

BODMAS stands for Brackets, Order, Divide, Multiply, Add, Subtract

Since multiplication comes first

s= 158+46×−1 => s= 158-46 => s= 112. :)

Mahie
  • 21