mersenneforum.org Expression evaluation
 Register FAQ Search Today's Posts Mark Forums Read

 2019-08-03, 09:47 #1 Nick     Dec 2012 The Netherlands 17×103 Posts Expression evaluation We all know that different processors may give different answers when evaluating -3 mod 2. But it was news to me that calculators differ in their evaluation of 8÷2(2+2): https://www.nytimes.com/2019/08/02/s...as-bedmas.html They avoid trying to explain to a general audience that $$2^{2^3}=256$$...
 2019-08-03, 12:18 #2 axn     Jun 2003 3×17×101 Posts 8÷2(2+2) is an inconsistent notation, mixing explicit division operator and implicit multiplication operator, so naturally there can be differences in the interpretation.
2019-08-03, 13:56   #3
xilman
Bamboozled!

"𒉺𒌌𒇷𒆷𒀭"
May 2003
Down not across

1095610 Posts

Quote:
 Originally Posted by axn 8÷2(2+2) is an inconsistent notation, mixing explicit division operator and implicit multiplication operator, so naturally there can be differences in the interpretation.
BODMAS (in UK schools) BEDMAS (in US ditto) removes any ambiguity.

 2019-08-03, 14:18 #4 a1call     "Rashid Naimi" Oct 2015 Remote to Here/There 23·269 Posts Takes away the ambiguity by giving precedence to division over multiplication, which are actually meant to have equal precedence which by original (before democratically acronym based convention) convention should be evaluated left-to-right, whichever comes 1st.
 2019-08-03, 14:35 #5 a1call     "Rashid Naimi" Oct 2015 Remote to Here/There 23×269 Posts I think it is ok for the masses to democratically decide who the experts are, but not to democratically decide what the expert-opinion is and leave that part to the experts in the field. Otherwise we get Wikipedia. Last fiddled with by a1call on 2019-08-03 at 14:36
2019-08-03, 20:27   #6
a1call

"Rashid Naimi"
Oct 2015
Remote to Here/There

23·269 Posts

Quote:
 Originally Posted by xilman BODMAS (in UK schools) BEDMAS (in US ditto) removes any ambiguity.
My hat off to you sir. It took me a good 2 hours to comprehend what you said.

Last fiddled with by a1call on 2019-08-03 at 20:28

2019-08-03, 23:52   #7
ewmayer
2ω=0

Sep 2002
República de California

22×5×11×53 Posts

Quote:
 Originally Posted by a1call Takes away the ambiguity by giving precedence to division over multiplication, which are actually meant to have equal precedence which by original (before democratically acronym based convention) convention should be evaluated left-to-right, whichever comes 1st.
No - the article's description of the convention makes clear that D,M and A,S are treated as equal-precedence operation pairs, with left-to-right breaking the resulting ties. Since C lacks an exponentiation operator this related issue does not arise there, but in my college engineering freshman Fortran class, there it was made clear that with multiple exponentiations in sequence, a**b**c (e.g. a^b^c using symbology more familiar to most of our readers), the order of evaluation is instead right-to-left, i.e. the above is interpreted as a^(b^c), so e.g. 2^3^4 gives 2^(3^4) = 2417851639229258349412352, not (2^3)^4 = 4096.

I tested both the expression in the OP and 2^3^4 using Posix bc, it conforms to the PEMDAS, including the above rule for exponentiation.

In related flamebait news, is it good or bad that C gives << and >> different priority than * and /?

 2019-08-04, 03:02 #8 Kebbaj     "Kebbaj Reda" May 2018 Casablanca, Morocco 2·47 Posts Reading direction Reading direction 8÷ 2(2+2). https://www.mersenneforum.org/showth...038#post523038 Attached Thumbnails   Last fiddled with by Kebbaj on 2019-08-04 at 03:07
2019-08-04, 07:24   #9
Nick

Dec 2012
The Netherlands

17×103 Posts

Quote:
 Originally Posted by ewmayer In related flamebait news, is it good or bad that C gives << and >> different priority than * and /?
It is, at least, easy to remember (coming just before < and >).
In my experience, code involving shifts also uses other bitwise operators so you end up needing brackets anyway, e.g.
Code:
t=(p<<5|p>>27)+(q&r^~q&s)+t+0x5a827999+tedoen[0];q=q<<30|q>>2;
(cryptonerds will recognize SHA).

 Similar Threads Thread Thread Starter Forum Replies Last Post jnml Miscellaneous Math 7 2018-09-06 15:57 MattcAnderson Homework Help 5 2016-11-01 08:16 tapion64 PrimeNet 10 2014-04-09 22:21 ixfd64 Programming 2 2009-03-01 06:19 jinydu Puzzles 9 2004-04-02 01:03

All times are UTC. The time now is 04:03.

Mon Oct 25 04:03:09 UTC 2021 up 93 days, 22:32, 0 users, load averages: 1.74, 1.26, 1.13