Path: utzoo!utgpu!water!watmath!clyde!rutgers!sunybcs!boulder!hao!gatech!mcnc!decvax!decwrl!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: power operator Summary: min and max once existed Message-ID: <518@cresswell.quintus.UUCP> Date: 10 Jan 88 03:40:35 GMT References: <11182@brl-adm.ARPA> <2197@haddock.ISC.COM> Organization: Quintus Computer Systems, Mountain View, CA Lines: 45 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. Admittedly, when I got my hands on the compiler, it didn't generate correct code for /\ and \/, but that was easy to fix. When we moved "up" to a PCC-based compiler, conversion was a pain. It is interesting that macros don't give you quite the same thing. Suppose I write x = low_bound \/ a /\ high_bound; This might compile into movl low_bound,r1 movl a,r0 cmpl r1,r0 bles 1f movl r1,r0 1: movl high_bound,r1 cmpl r1,r0 bges 2f movl r1,r0 2: movl r0,x Now suppose I have #define max(a,b) ((a)<(b)?(b):(a)) #define min(a,b) ((a)>(b)?(b):(a)) and write x = min(max(low_bound,a),high_bound); Modulo parentheses, this expands to x = ( (low_bound < a ? a : low_bound) > high_bound ? (low_bound < a ? a : low_bound) : high_bound ); That's three conditionals, not two. An optimising compiler could be expected to recognise the common sub-expression, but why put it to the trouble? This "clipping" form is what I mostly used, but maximum or minimum of more than two elements is reasonably common, and has the same problem. The macros make a most unsatisfactory ersatz. So there is prior art for /\ and \/ in C. Fortran, of course, has them too. Apparently Fortran programmers do not think it a great burden to write MIN(I,J) rather than I/\J. Do I think it would be a good idea to add the to the standard? No. Standards should be DISCOVERED, not INVENTED. (It was *years* before COBOL 74 was generally available. In fact the next version of the standard was already out...)