One of my recently acquired command line tip, create this function

? () { echo "$*" | bc ; }

usage

$> ? 8*5
40
$> ? 2+2+9*9+(2-8)
79

No need to create a python process or node process ( or any other interactive shell ) for quick calculation. It just takes the mathematical query and throw it to BC which then return the result.

In case it isn't obvious, Question mark ? is just a name of function. You can choose anything else as long as it doesn't conflict the system.

Also bc is a mathematical tool, it follows bodmas or pemdas order of operation. So 6 ÷ 2(1+2)= is equal to 1, not 9, not 7, or any other thing you saw on facebook. I should have checked on my machine before bashing out here, My casio calculator outputs 1 because of implied multiplication taking precedence, so does what we are taught in schools in India, but apparently precedence of implied multiplication is standardized to be ignored since 1917.

Bodmas, pemdas or any other weird word is just a pitfall to trick people into mistakes, and gladly I have never heard such terms in school. Division and multiplication are performed in the order they appear, it could not be simpler. Division, in fact, is multiplication, just like subtraction is the same as addition. When you divide by 5, you are in fact multiplying by the inverse of 5. There is no reason to perform multiplication before division, since they are the same thing.

I couldn't believe BC would output 1, so I opened a terminal and ran it, and of course it showed 9 in the screen.

Well apparently, In India, we were taught the older method. I did some search and find this video from "mind-your-decision" and what we were taught is the older 1917 order of operation, where parentheses next to number has special exception. My old casio calculator actually outputs "1", because they have implied multiplication

I know that division and multiplication have same level of order and hence calculated left to right. Bodmas doesn't mean addition before subtraction, but it does mean division(or multiplication) happens before subtraction(or addition) and exponents(or log) happens before them, and brackets always have higher priority. The operators with same specificity are solved left-to-right.

Thanks for correcting me. I wrote it as a sarcasm on all the stupid fb posts and twitter polls that have been going around my feeds, but turns out it was a facepalm moment. "Implied multiplication" is still taught in schools in India.

For further actions, you may consider blocking this person and/or reporting abuse

We're a place where coders share, stay up-to-date and grow their careers.

One of my recently acquired command line tip, create this function

usage

No need to create a python process or node process ( or any other interactive shell ) for quick calculation. It just takes the mathematical query and throw it to BC which then return the result.

In case it isn't obvious, Question mark

`?`

is just a name of function. You can choose anything else as long as it doesn't conflict the system.~~Also~~I should have checked on my machine before bashing out here, My casio calculator outputs 1 because of implied multiplication taking precedence, so does what we are taught in schools in India, but apparently precedence of implied multiplication is standardized to be ignored since 1917.`bc`

is a mathematical tool, it followsbodmasorpemdasorder of operation. So`6 ÷ 2(1+2)=`

is equal to 1, not 9, not 7, or any other thing you saw on facebook.Sorry, but

`6 ÷ 2(1+2)`

is just 9, indisputably.Bodmas, pemdas or any other weird word is just a pitfall to trick people into mistakes, and gladly I have never heard such terms in school. Division and multiplication are performed in the order they appear, it could not be simpler. Division, in fact,

ismultiplication, just like subtraction is the same as addition. When you divide by 5, you are in fact multiplying by the inverse of 5. There is no reason to perform multiplication before division, since they are the same thing.I couldn't believe BC would output 1, so I opened a terminal and ran it, and of course it showed 9 in the screen.

Well apparently, In India, we were taught the older method. I did some search and find this video from "mind-your-decision" and what we were taught is the older 1917 order of operation, where parentheses next to number has special exception. My old casio calculator actually outputs "1", because they have implied multiplication

I know that division and multiplication have same level of order and hence calculated left to right.

Bodmas doesn't mean addition before subtraction,but it does mean division(or multiplication) happens before subtraction(or addition) and exponents(or log) happens before them, and brackets always have higher priority. The operators with same specificity are solved left-to-right.Thanks for correcting me. I wrote it as a sarcasm on all the stupid fb posts and twitter polls that have been going around my feeds, but turns out it was a facepalm moment. "Implied multiplication" is still taught in schools in India.