Re: [AD] MID revisited

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


On 2007-08-06, Matthew Leverton <meffer@xxxxxxxxxx> wrote:
> See bug #1640516 for reference and earlier threads for past discussions.
> 
> In short, the Allegro MID is a misnomer, as it really clamps between x
> and z with the assumption that x is not greater than z. So, for
> example, MID(5,y,0) will give unpredictable results.
> 
> The examples make use of MID, so it really is a public macro, even if
> it isn't publicly documented (yet).
> 
> There are two choices:
> 
> 1) Ignore it, but document it.
> 2) Rename MID to CLAMP and provide a proper MID.
> 
> I prefer #2, as it actually addresses the problem.
> 
> The two drawbacks of #2 are:
> 
> 1) MID() is bound to be slightly slower than CLAMP(). So people
> currently using MID() in add-ons, etc should change their code
> accordingly. The macro I'm proposing only uses two comparisons for the
> "in order" where x < y < z, which is the same as MID(). It uses three
> comparisons for all other cases (except x > y > z, which takes two).
> 
> 2) If such 3rd party code is changed to CLAMP(), the code would need
> to maintain a version check and #define CLAMP MID if the code is meant
> to work with 4.2 and previous. (Mainly affects libraries.)
> 
> Attached is a patch against 4.3.10plus and a test program. You can see
> the output of the test program here: <http://pastebin.com/f5a19542>
> 
> So it would be nice to make a definite decision one way or the other
> regarding this.

Let's go with #2.  The patch looks fine.  We should consider actually
documenting them as well :-)

Peter





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