microsoft / calculator

Windows Calculator: A simple yet powerful calculator that ships with Windows
MIT License
29.7k stars 5.38k forks source link

Calculator doesn't adhere to Bodmas or Pemdas rules #1587

Closed cyberangel67 closed 3 years ago

cyberangel67 commented 3 years ago

Scientific Mode

Unless I am doing something wrong, if we look at the following math equation

8/2(2+2) = ?

If we follow the principle of BODMAS and PEMDAS, this should equate to

8/2x4

This then equates to

8/8

which equals 1

So why does the calculator not follow these BODMAS and PEMDAS rules, when giving an answer? As far back as I have been using Windows, the calculator has never followed these rules.

When entering this into the Calculator one has to enter it

8 / 2 x ( 2 + 2 )

and it still gives the answer as 16, and not the correct answer 1,

And it will not work with

8/2(2+2)

mdtauk commented 3 years ago

This has been discussed before, Scientific mode should follow BODMAS, but Standard mode performs each operation in succession

1464 #1212 #1436 #138

MicrosoftIssueBot commented 3 years ago

This is your friendly Microsoft Issue Bot. I've seen this issue come in and have gone to tell a human about it.

cyberangel67 commented 3 years ago

This has been discussed before, Scientific mode should follow BODMAS, but Standard mode performs each operation in succession

1464 #1212 #1436 #138

This is Scientific mode, that was the first thing I stated!

mdtauk commented 3 years ago

This has been discussed before, Scientific mode should follow BODMAS, but Standard mode performs each operation in succession

1464 #1212 #1436 #138

This is Scientific mode, that was the first thing I stated!

Ah ok, then it may not be totally related to the other issues. I think I have seen this mentioned before though. I think its an issue with how the Calculator handles input, when you enter a number and open the brackets, it ignores the number...

https://user-images.githubusercontent.com/7389110/122587244-81002500-d055-11eb-9bf1-43e311175410.mp4

cyberangel67 commented 3 years ago

But you are also ignoring the rest of what I said as well!

cyberangel67 commented 3 years ago

Here is another very basic PEMDAS example not working correctly in the calculator on Scientific Mode.

18÷(8-2×3)

The answer is obviously 9. yet the calculator says it is 4!

mdtauk commented 3 years ago

Does it? image

cyberangel67 commented 3 years ago

And another

(4×3÷6+1)×3^2

The answer should be 27, I am not sure how the calculator is breaking this down, but the correct way is

Step 1- First, we need to multiply 4 by 3 in the given expression, ​​​​​(4×3÷6+1)×3^2, we get, ​​(12÷6+1)×3^2

Step 2- Now, we need to divide 12 by 6 inside the bracket, so, we get, (2+1)×3^2

Step 3- Remove parentheses after adding 2 and 1, we get, 3×3^2

Step 4- Solve exponent, i.e 3^2, which is 9, 3×9

Step 5- Multiply 3 by 9 to get the final answer, which is, 3×9= 27

∴ ​(4×3÷6+1)×3^2= 27.

Edit : 2nd time entering this I get 27...

cyberangel67 commented 3 years ago

Does it? image

Not what I got

Edit: Did it a 3rd time and got 9, first two I got 4.

grochocki commented 3 years ago

According to order of operations, multiplication/division are performed sequentially left-to-right (not multiplication first, followed by division).

So the expected output of the original expression 8/2(2+2) is 16, which is what I am seeing in scientific mode:

image

For the second example, the expected output of 18÷(8-2×3) is 9, which is what I am seeing in scientific mode:

image

And for the third example, the expected output of (4*3/6+1)*3^2 is 27, which is what I am seeing in scientific mode:

image

I am not able to reproduce any violations of order of operations when expanding the expressions, so I am going to close this as no repro. Due to #1498, some input may be ignored under certain circumstances, so I suspect you may be encountering this issue.