Yeah, the signed/unsigned thing can be surprising. IIRC if x is unsigned then x < 0 is never true but x == -1 might be true.
I knew about 3[foo] being equivalent to foo[3]. I find it astonishing but know that it is true (and understand why, more or less). Charles -----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Paul Gilmartin Sent: Saturday, July 18, 2020 10:59 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: OOBOL and English was Re: Still COBOL After All These Years? On Sat, 18 Jul 2020 08:20:09 -0700, Charles Mills wrote: >Or, more formally, addition is commutative but subtraction is not. > >A + B always* equals B + A, but A - B generally does not equal B - A. > >*Is that true for computer languages (as opposed to being true only for pure >math)? In modern C++ if I say > >auto x = y + z; > >If y and z are of different types (float and integer; 64-bit and 32-bit) does >x take the type of the first operand, and thus y + z yields a different result >than z + y? > I think it's mostly dominant type. But there may have been a transition from unsigned-preserving to value-preserving. So it may no longer be true that -1 > (unsigned)0. Since C defines subscripting in terms of addition and addition is commutative, "wombat"[3] may be written as 3["wombat"]; both evaluate to 'b'. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN