[gimp] libgimpmath: add SAFE_CLAMP() macro



commit e9f45798d06983ef1dd3fffb60524111bb7f6335
Author: Ell <ell_se yahoo com>
Date:   Sun Nov 19 07:07:20 2017 -0500

    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.

 libgimpmath/gimpmath.h |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/libgimpmath/gimpmath.h b/libgimpmath/gimpmath.h
index b7f5d6a..c26acc3 100644
--- a/libgimpmath/gimpmath.h
+++ b/libgimpmath/gimpmath.h
@@ -118,6 +118,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.
  *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]