clamp.hpp

Go to the documentation of this file.
00001 
00021 #ifndef __MLPACK_CORE_MATH_CLAMP_HPP
00022 #define __MLPACK_CORE_MATH_CLAMP_HPP
00023 
00024 #include <stdlib.h>
00025 #include <math.h>
00026 #include <float.h>
00027 
00028 namespace mlpack {
00029 namespace math  {
00030 
00038 inline double ClampNonNegative(const double d)
00039 {
00040   return (d + fabs(d)) / 2;
00041 }
00042 
00050 inline double ClampNonPositive(const double d)
00051 {
00052   return (d - fabs(d)) / 2;
00053 }
00054 
00063 inline double ClampRange(double value,
00064                          const double rangeMin,
00065                          const double rangeMax)
00066 {
00067   value -= rangeMax;
00068   value = ClampNonPositive(value) + rangeMax;
00069   value -= rangeMin;
00070   value = ClampNonNegative(value) + rangeMin;
00071   return value;
00072 }
00073 
00074 }; // namespace math
00075 }; // namespace mlpack
00076 
00077 #endif // __MLPACK_CORE_MATH_CLAMP_HPP

Generated on 13 Aug 2014 for MLPACK by  doxygen 1.6.1