Re: Why no min / max
- From: Tom St Denis <tom@xxxxxxx>
- Date: Fri, 26 Nov 2010 07:58:04 -0800 (PST)
On Nov 26, 10:54 am, Eric Sosman <esos...@xxxxxxxxxxxxxxxxxxxx> 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.
What is the rationale for this omission in C89? in C99?
Mu.
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 ...
Simple just do MIN(MIN(x,y),MIN(y,x)).
Solved.
Tom
.
- Follow-Ups:
- Re: Why no min / max
- From: James Dow Allen
- Re: Why no min / max
- References:
- Why no min / max
- From: Noob
- Re: Why no min / max
- From: Eric Sosman
- Why no min / max
- Prev by Date: Re: Why no min / max
- Next by Date: ANGELINA JOLIE New***Tape Released ( UNSEEN Video Ever Seen ) Erotic Video
- Previous by thread: Re: Why no min / max
- Next by thread: Re: Why no min / max
- Index(es):