libgimpmath: add SAFE_CLAMP() macro

The SAFE_CLAMP() macro is similar to CLAMP(), however, its result
is always within the specified range, even if the input is NaN.
This commit is contained in:
Ell
2017-11-19 07:07:20 -05:00
parent 5eb6187421
commit e9f45798d0

View File

@ -117,6 +117,20 @@ G_BEGIN_DECLS
**/
#define CLAMP0255(a) CLAMP(a,0,255)
/**
* SAFE_CLAMP:
* @x: the value to be limited.
* @low: the lower limit.
* @high: the upper limit.
*
* Ensures that @x is between the limits set by @low and @high,
* even if @x is NaN. If @low is greater than @high, or if either
* of them is NaN, the result is undefined.
*
* Since: 2.10
**/
#define SAFE_CLAMP(x, low, high) ((x) > (low) ? (x) < (high) ? (x) : (high) : (low))
/**
* gimp_deg_to_rad:
* @angle: the angle to be converted.