Eric Sosman wrote:
> On 11/26/2010 10:12 AM, Noob wrote:
>>
>> As far as I can tell, the standard library does not provide
>> functions (or macros) to compute the minimum and maximum of
>> two values, be they integral values, or floating point values;
>> leaving it up to each programmer in the world to roll their own.
>> Is this correct?
>
> No; you've overlooked the fmax(), fmin(), fmaxf(), fminf(),
> fmaxl(), and fminl() functions.
Right.
7.12.12.2 The fmax functions
double fmax(double x, double y);
float fmaxf(float x, float y);
long double fmaxl(long double x, long double y);
7.12.12.3 The fmin functions
double fmin(double x, double y);
float fminf(float x, float y);
long double fminl(long double x, long double y);
Allow me to revise my statement:
As far as I can tell, the standard library does not provide
functions (or macros) to compute the minimum and maximum of
two integral values. Is this correct?
What is the rationale for this omission in C89? in C99?
>> Is it because it is "simple" to implement as a macro?
>> Something along the lines of #define MIN(a,b) (((a)<(b))?(a)
b))
>
> With the usual caveats about macros and side-effects, this is
> a reasonable implementation for many cases. Note that it is *not*
> reasonable for a system supporting floating-point NaN's: MIN(NaN,42)
> could yield 42, while MIN(42,NaN) could yield NaN. I think most
> people would find a non-commutative MIN surprising ...
As far as integer min/max is concerned, I suppose it would be
complicated to add them at this point? Because the whole world+dog
rolled their own (possibly slightly incompatible) version.
Regards.