Path: utzoo!utgpu!water!watmath!clyde!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: min and max Message-ID: <2254@haddock.ISC.COM> Date: 14 Jan 88 01:43:27 GMT References: <11182@brl-adm.ARPA> <2197@haddock.ISC.COM> <518@cresswell.quintus.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 37 In article <518@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >In article <2197@haddock.ISC.COM>, karl@haddock.ISC.COM (Karl Heuer) writes: >> Actually, I'd give a higher wish-priority to min and max operators. They >> could have used "><" and "<>", respectively; the syntax would drive BASIC >> and PASCAL users crazy! :-) > >Some years ago the C compiler I used *did* have min (spelled "/\") >and max (spelled "\/") operators. These symbols are ever so much better >because they are standard mathematical notation. Okay, as long as you're careful not to put "/\" at the end of a line. (ANSI Backslash continuation occurs before token scanning!) >["lo \/ a /\ hi" is likely to generate less code than the macros would.] Right. One thing I like about that idiom is that, assuming lo <= hi, the relative precedence/associativity of \/ and /\ is irrelevant. In addition to the usual min() and max() functions, I keep a med() function in my library: med(lo, x, hi) returns lo \/ x /\ hi if lo <= hi; undefined if lo > hi. (I could easily remove the lo <= hi restriction and have it always return the median of the three numbers, but I've never needed that functionality and I wanted to keep the implementation simple.) Of course, the assignment operators /\= and \/= would be great. Think of all the times you've ever written "if (x > xmax) xmax = x;". >Do I think it would be a good idea to add the to the standard? No. Despite my posted enthusiasm for these and the exponentiation operator, I must agree. There isn't enough prior art. I would like to see it become a common extension, though. What's the appropriate precedence for these operators? (What was it on those compilers that had this extension?) Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint (Btw, I believe "><" and "<>" are used in SAS for min and max operators.)