ph@miro.Berkeley.EDU (Paul Heckbert) (04/11/88)
Beware of doing arithmetic in csh, it's buggy! The command @ x = 0 - 1 + 2 sets x to -3 (should be 1) The command @ x = 0 - 1 - 2 sets x to 1 (should be -3) (same error with Sun UNIX 3.5 on Sun3 and 4.3 BSD on Vax780) csh must be parsing right-associatively by mistake! Division has a similar problem. It's hard to believe that a bug like this would persist for 8 years. Paul Heckbert, CS grad student 508-7 Evans Hall, UC Berkeley UUCP: ucbvax!miro.berkeley.edu!ph Berkeley, CA 94720 ARPA: ph@miro.berkeley.edu
mesard@bbn.com (Wayne Mesard) (04/11/88)
From article <23570@ucbvax.BERKELEY.EDU>, by ph@miro.Berkeley.EDU (Paul Heckbert): > Beware of doing arithmetic in csh, it's buggy! > > The command @ x = 0 - 1 + 2 sets x to -3 (should be 1) > > The command @ x = 0 - 1 - 2 sets x to 1 (should be -3) > > (same error with Sun UNIX 3.5 on Sun3 and 4.3 BSD on Vax780) > > csh must be parsing right-associatively by mistake! > Division has a similar problem. > > It's hard to believe that a bug like this would persist for 8 years. > From csh(1): :Expressions and Operators :[...] : * / % : multiplication, division, remainder (These are right : associative, which can lead to unexpected results. : Group combinations explicitly with parentheses.) : + - : addition, subtraction (also right associative) It looks like a bug, it acts like a bug, but if it's documented... -- unsigned *Wayne_Mesard(); MESARD@BBN.COM BBN Labs, Cambridge, MA
thompson@dalcs.UUCP (Michael Thompson) (04/11/88)
In article <23570@ucbvax.BERKELEY.EDU> ph@miro.Berkeley.EDU (Paul Heckbert) writes: >Beware of doing arithmetic in csh, it's buggy! >The command @ x = 0 - 1 + 2 sets x to -3 (should be 1) >The command @ x = 0 - 1 - 2 sets x to 1 (should be -3) >(same error with Sun UNIX 3.5 on Sun3 and 4.3 BSD on Vax780) > >csh must be parsing right-associatively by mistake! >Division has a similar problem. >It's hard to believe that a bug like this would persist for 8 years. The following is extracted from the csh man page: * / % multiplication, division, remainder (These are right associative, which can lead to unexpected results. Group combinations explicitly with parentheses.) + - addition, subtraction (also right associative) -- <<<<<<******>>>>>> Michael A. Thompson, Dept. Math, Stats, & C.S., Dalhousie U., Halifax, N.S. thompson@dalcs.uucp | thompson@cs.dal.cdn | thompson@dal1.bitnet (902)424-6501
greim@sbsvax.UUCP (Michael Greim) (04/12/88)
In <23570@ucbvax.BERKELEY.EDU> Paul Heckbert writes : >Beware of doing arithmetic in csh, it's buggy! > >The command @ x = 0 - 1 + 2 sets x to -3 (should be 1) > >The command @ x = 0 - 1 - 2 sets x to 1 (should be -3) > >(same error with Sun UNIX 3.5 on Sun3 and 4.3 BSD on Vax780) > >csh must be parsing right-associatively by mistake! >Division has a similar problem. > >It's hard to believe that a bug like this would persist for 8 years. I just checked: the 4.3BSD manual does not mention any peculiarities. But according to the SUN manual, * / % + and - are right associative. (Maybe they just corrected the manual to conform with the program :-) Does this weird behavior require fixing ? (should we vote ? :-) Michael +------------------------------------------------------------------------------+ | UUCP: ...!uunet!unido!sbsvax!greim | Michael T. Greim | | or greim@sbsvax.UUCP | Universitaet des Saarlandes | | CSNET: greim%sbsvax.uucp@Germany.CSnet| FB 10 - Informatik (Dept. of CS) | | ARPA: greim%sbsvax.uucp@uunet.UU.NET | Bau 36, Im Stadtwald 15 | | Phone: +49 681 302 2434 | D-6600 Saarbruecken 11, West Germany | +------------------------------------------------------------------------------+ | Watch this space. Don't let it escape. | +------------------------------------------------------------------------------+