Re: [AD] [ alleg-Bugs-1640516 ] MID() gives incorrect results

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


it's supposed to and the Allegro source always uses it correctly---but it
is misnamed and causes confusion.  MID() is undocumented so users
shouldn't actually depend on it, but I'm afraid many people *do*.  We can
compromise by fixing MID(), and introduce CLAMP() for the old behaviour
(if necessary).  But even then, I'd recommend not depending on the fixed
behaviour so your programs don't fail subtly if compiled with an older
version of Allegro.


This version uses fewer comparisons:

#define MID(x,y,z) ((x) > (y) ? ((y) > (z) ? (y) : ((x) > (z) ? (z) :
(x))) : ((y) > z ? ((z) > (x) ? (z) : (x)) : (y)))

For example on the OP's version, 331 requires 8 comparisons. In this
version, it's either 2 or 3 comparisons.

I think it would be good to rename MID to CLAMP and introduce a proper
MID macro. [For those who aren't aware, Allegro always uses it like
MID(0, value, 255) to make sure a value is between two others.]

I don't really see how it could break anything, because anyone relying
on MID to do anything useful (besides what Allegro does) has got to
have one of the weiderst programs ever written...

--
Matthew Leverton




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/