MorphoGraphX  2.0-1-227
Clamp.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef CLAMP_H
12 #define CLAMP_H
13 
14 #include <Config.hpp>
15 
22 //#include <config.h>
23 namespace mgx
24 {
33  template <class T> T clamp(const T& val, const T& min, const T& max)
34  {
35  if(min >= max)
36  return max;
37  else if(val < min)
38  return min;
39  else if(val > max)
40  return max;
41  else
42  return val;
43  }
44 }
45 
46 #endif
mgx::clamp
T clamp(const T &val, const T &min, const T &max)
A function to clamp a value to a range.
Definition: Clamp.hpp:33
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::max
T CU_HOST_DEVICE max(const T a, const T b)
Definition: Util.hpp:34
mgx::min
CU_HOST_DEVICE T min(const T a, const T b)
Definition: Util.hpp:26