Extrema C/C++ Macros
by Stanislav Sýkora, Extra Byte, Via R.Sanzio 22C, Castano Primo, Italy 20022
in Stan's Library, Ed.S.Sykora, Vol.I. First release April 15, 2004.
Permalink via DOI:  10.3247/SL1Soft06.004
PREVIOUS | NEXT | Code snippets | Software Books and Links Programming Section of Stan' LIBRARY | Stan's HUB

This document is a part of a collection of macros. For introductory remarks, see the first part (General Purpose Macros).
For a review of macro-syntax rules and related tips and tricks, see Writing Macros.
For the typedefs DWORD, WORD, BYTE and CHAR, click here.

CATEGORY MACRO
MAXIMUM and MINIMUM
Values
mMax, mMax2, mMax3, mMax4, mMax5, mMax6
mMin, mMin2, mMin3, mMin4, mMin5, mMin6
MAXIMUM and MINIMUM
Absolute Values
mMaxAbs, mMaxAbs2, mMaxAbs3, mMaxAbs4, mMaxAbs5, mMaxAbs6
mMinAbs, mMinAbs2, mMinAbs3, mMinAbs4, mMinAbs5, mMinAbs6
EXTREME Values (signed) mExtreme, mExtreme2, mExtreme3, mExtreme4, mExtreme5, mExtreme6
RANGES mRange, mRange2, mRange3, mRange4, mRange5, mRange6

Maximum and Minimum Values

Code:

#define mMax(a,b) (mIsGT(b,a)?(b):(a))
#define mMax2(a,b) mMax(a,b)
#define mMax3(a,b,c) mMax(a,mMax(b,c))
#define mMax4(a,b,c,d) mMax(mMax(a,b),mMax(c,d))
#define mMax5(a,b,c,d,e) mMax(mMax(a,b),mMax3(c,d,e))
#define mMax6(a,b,c,d,e,f) mMax(mMax3(a,b,c),mMax3(d,e,f))

#define mMin(a,b) (mIsLT(b,a)?(b):(a))
#define mMin2(a,b) mMin(a,b)
#define mMin3(a,b,c) mMin(a,mMin(b,c))
#define mMin4(a,b,c,d) mMin(mMin(a,b),mMin(c,d))
#define mMin5(a,b,c,d,e) mMin(mMin(a,b),mMin3(c,d,e))
#define mMin6(a,b,c,d,e,f) mMin(mMin3(a,b,c),mMin3(d,e,f))

Arguments:

a through f stand for any entities (including expressions) which are compatible with the relational operators > (for maximum searches) or < (for minimum searches).

These macros rely on the macros mIsGT and mIsLT.


mMax(a,b),
mMax2(a,b),
mMax3(a,b,c),
mMax4(a,b,c,d),
mMax5(a,b,c,d,e),
mMax6(a,b,c,d,e,f)
return the largest value of their arguments.
mMin(a,b),
mMin2(a,b),
mMin3(a,b,c),
mMin4(a,b,c,d),
mMin5(a,b,c,d,e),
mMin6(a,b,c,d,e,f)
return the smallest value of their arguments.

Maximum and Minimum Absolute Values

Code:

#define mMaxAbs(a,b) mMax(mAbs(a),mAbs(b))
#define mMaxAbs2(a,b) mMaxAbs(a,b)
#define mMaxAbs3(a,b,c) mMax3(mAbs(a),mAbs(b),mAbs(c))
#define mMaxAbs4(a,b,c,d) mMax4(mAbs(a),mAbs(b),mAbs(c),mAbs(d))
#define mMaxAbs5(a,b,c,d,e) mMax5(mAbs(a),mAbs(b),mAbs(c),mAbs(d),mAbs(e))
#define mMaxAbs6(a,b,c,d,e,f) mMax6(mAbs(a),mAbs(b),mAbs(c),mAbs(d),mAbs(e),mAbs(f))

#define mMinAbs(a,b) mMin(mAbs(a),mAbs(b))
#define mMinAbs2(a,b) mMinAbs(a,b)
#define mMinAbs3(a,b,c) mMin3(mAbs(a),mAbs(b),mAbs(c))
#define mMinAbs4(a,b,c,d) mMin4(mAbs(a),mAbs(b),mAbs(c),mAbs(d))
#define mMinAbs5(a,b,c,d,e) mMin5(mAbs(a),mAbs(b),mAbs(c),mAbs(d),mAbs(e))
#define mMinAbs6(a,b,c,d,e,f) mMin6(mAbs(a),mAbs(b),mAbs(c),mAbs(d),mAbs(e),mAbs(f))

Arguments:

a through f stand for any entities (including expressions) which are compatible with the relational operators > (for maximum searches) or < (for minimum searches).

These macros rely on the relational macros mIsGT, mIsLT and mAbs.


mMaxAbs(a,b),
mMaxAbs2(a,b),
mMaxAbs3(a,b,c),
mMaxAbs4(a,b,c,d),
mMaxAbs5(a,b,c,d,e),
mMaxAbs6(a,b,c,d,e,f)
return the largest of the absolute values of their arguments.
mMinAbs(a,b),
mMinAbs2(a,b),
mMinAbs3(a,b,c),
mMinAbs4(a,b,c,d),
mMinAbs5(a,b,c,d,e),
mMinAbs6(a,b,c,d,e,f)
return the smallest of the absolute values of their arguments.

Extreme Values (signed)

Code:

#define mExtreme(a,b) (mIsGT(mAbs(b),mAbs(a))?(b):(a))
#define mExtreme2(a,b) mExtreme(a,b)
#define mExtreme3(a,b,c) mExtreme(a,mExtreme(b,c))
#define mExtreme4(a,b,c,d) mExtreme(mExtreme(a,b),mExtreme(c,d))
#define mExtreme5(a,b,c,d,e) mExtreme(mExtreme(a,b),mExtreme3(c,d,e))
#define mExtreme6(a,b,c,d,e,f) mExtreme(mExtreme3(a,b,c),mExtreme3(d,e,f))

Arguments:

a through f stand for any entities (including expressions) which are compatible with the relational operator >.

These macros rely on the relational macro mIsGT.


mExtreme(a,b),
mExtreme2(a,b),
mExtreme3(a,b,c),
mExtreme4(a,b,c,d),
mExtreme5(a,b,c,d,e),
mExtreme6(a,b,c,d,e,f)
return the (signed) value of the argument which has the largest absolute value.

Ranges

Code:

#define mRange(a,b) (mMax(a,b)-nMin(a,b))
#define mRange2(a,b) mRange(a,b)
#define mRange3(a,b,c) (mMax(a,b,c)-nMin(a,b,c))
#define mRange4(a,b,c,d) (mMax(a,b,c,d)-nMin(a,b,c,d))
#define mRange5(a,b,c,d,e) (mMax(a,b,c,d,e)-nMin(a,b,c,d,e))
#define mRange6(a,b,c,d,e,f) (mMax(a,b,c,d,e,f)-nMin(a,b,c,d,e,f))

Arguments:

a through f stand for any entities (including expressions) which are compatible with the relational operator >.

These macros rely on the relational macro mIsGT.


mRange(a,b),
mRange2(a,b),
mRange3(a,b,c),
mRange4(a,b,c,d),
mRange5(a,b,c,d,e),
mRange6(a,b,c,d,e,f)
return the difference between the maximum and minimum argument values.
TOP | PREVIOUS | NEXT | Code snippets | Software Books and Links Programming Section of Stan' LIBRARY | Stan's HUB
Copyright ©2004,2006 Stanislav Sýkora    DOI: 10.3247/SL1Soft06.004 Designed by Stan Sýkora