View Single Post
Old 03-13-2023, 12:12 AM   #1405
Solitaire1
Samurai Lizard
Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.Solitaire1 ought to be getting tired of karma fortunes by now.
 
Solitaire1's Avatar
 
Posts: 14,957
Karma: 70029956
Join Date: Nov 2009
Device: NookColor, Nook Glowlight 4
Quote:
Originally Posted by j.p.s View Post
Yeah, that too. I don't know which upsets me more, that, or that C compilers, by default, feel free to ignore arithmetic operator precedence, even when parentheses are used to (attempt to) force operation order.
This is a related issue involving Order of Operations. An issue with it is that two different calculators can work the same expression and come up with different answers. This is due to one calculator using implied multiplication and the other not using implied multiplication. Due to this, you have to use the right calculator, otherwise you might get the wrong answer.

The following video will explain the problem better than I can:


Due to this, I will use the following first step before applying PEMDAS which will fix the problem:

Conversion: Convert all of the divisions to multiplications, and all of the subtractions to additions.

Since addition and multiplication are commutative it simplifies the issue and eliminates some incorrect answers. As an example:

With the expression "3/2(4+8)" I'd first convert it to "3*0.5(4+8)" and then work it as follows:

- 3*0.5(12)
- 1.5*12
- 18

Although the video mentions it, it seems odd to me that all calculators don't work expressions the same way.
Solitaire1 is offline   Reply With Quote