Simbody  3.7

Limit a numerical value so that it does not go outside a given range. More...

Functions

double & SimTK::clampInPlace (double low, double &v, double high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range. More...
 
float & SimTK::clampInPlace (float low, float &v, float high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
double & SimTK::clampInPlace (int low, double &v, int high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range. More...
 
float & SimTK::clampInPlace (int low, float &v, int high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range. More...
 
double & SimTK::clampInPlace (int low, double &v, double high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range. More...
 
float & SimTK::clampInPlace (int low, float &v, float high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range. More...
 
double & SimTK::clampInPlace (double low, double &v, int high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range. More...
 
float & SimTK::clampInPlace (float low, float &v, int high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range. More...
 
unsigned char & SimTK::clampInPlace (unsigned char low, unsigned char &v, unsigned char high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
unsigned short & SimTK::clampInPlace (unsigned short low, unsigned short &v, unsigned short high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
unsigned int & SimTK::clampInPlace (unsigned int low, unsigned int &v, unsigned int high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
unsigned long & SimTK::clampInPlace (unsigned long low, unsigned long &v, unsigned long high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
unsigned long long & SimTK::clampInPlace (unsigned long long low, unsigned long long &v, unsigned long long high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
char & SimTK::clampInPlace (char low, char &v, char high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
signed char & SimTK::clampInPlace (signed char low, signed char &v, signed char high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
short & SimTK::clampInPlace (short low, short &v, short high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
int & SimTK::clampInPlace (int low, int &v, int high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
long & SimTK::clampInPlace (long low, long &v, long high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
long long & SimTK::clampInPlace (long long low, long long &v, long long high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
negator< float > & SimTK::clampInPlace (float low, negator< float > &v, float high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
negator< double > & SimTK::clampInPlace (double low, negator< double > &v, double high)
 Check that low <= v <= high and modify v in place if necessary to bring it into that range.
More...
 
double SimTK::clamp (double low, double v, double high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 
float SimTK::clamp (float low, float v, float high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
double SimTK::clamp (int low, double v, int high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 
float SimTK::clamp (int low, float v, int high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 
double SimTK::clamp (int low, double v, double high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 
float SimTK::clamp (int low, float v, float high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 
double SimTK::clamp (double low, double v, int high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 
float SimTK::clamp (float low, float v, int high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 
unsigned char SimTK::clamp (unsigned char low, unsigned char v, unsigned char high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
unsigned short SimTK::clamp (unsigned short low, unsigned short v, unsigned short high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
unsigned int SimTK::clamp (unsigned int low, unsigned int v, unsigned int high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
unsigned long SimTK::clamp (unsigned long low, unsigned long v, unsigned long high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
unsigned long long SimTK::clamp (unsigned long long low, unsigned long long v, unsigned long long high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
char SimTK::clamp (char low, char v, char high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
signed char SimTK::clamp (signed char low, signed char v, signed char high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
short SimTK::clamp (short low, short v, short high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
int SimTK::clamp (int low, int v, int high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
long SimTK::clamp (long low, long v, long high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
long long SimTK::clamp (long long low, long long v, long long high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.
More...
 
float SimTK::clamp (float low, negator< float > v, float high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 
double SimTK::clamp (double low, negator< double > v, double high)
 If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v. More...
 

Detailed Description

Limit a numerical value so that it does not go outside a given range.

There are two functions (plus overloads) defined here: clamp() and clampInPlace(). The first one is the most commonly used and simply calculates an in-range value from an input value and a given range [low,high]. clampInPlace() is given a reference to a variable and if necessary modifies that variable so that its value is in the given range [low,high]. Both functions are overloaded for all the integral and real types but are not defined for complex or conjugate types.

The following examples shows how clamp() and clampInPlace() can be defined in terms of std::min() and std::max().

clamp():

const double low, high; // from somewhere
const double v;
double clampedValue;
clampedValue = clamp(low,v,high); // clampedValue is in [low,high]
clampedValue = std::min(std::max(low,v), high); // equivalent

clampInPlace():

const double low, high; // from somewhere
double v;
clampInPlace(low,v,high); // now v is in [low,high]
v = std::min(std::max(low,v), high); // equivalent

Function Documentation

◆ clampInPlace() [1/21]

double& SimTK::clampInPlace ( double  low,
double &  v,
double  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [2/21]

float& SimTK::clampInPlace ( float  low,
float &  v,
float  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [3/21]

double& SimTK::clampInPlace ( int  low,
double &  v,
int  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops. Takes integer bounds to avoid need for explicit casts.

◆ clampInPlace() [4/21]

float& SimTK::clampInPlace ( int  low,
float &  v,
int  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops. Takes integer bounds to avoid need for explicit casts.

◆ clampInPlace() [5/21]

double& SimTK::clampInPlace ( int  low,
double &  v,
double  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops. Takes an integer bound to avoid need for explicit casts.

◆ clampInPlace() [6/21]

float& SimTK::clampInPlace ( int  low,
float &  v,
float  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops. Takes an integer bound to avoid need for explicit casts.

◆ clampInPlace() [7/21]

double& SimTK::clampInPlace ( double  low,
double &  v,
int  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops. Takes an integer bound to avoid need for explicit casts.

◆ clampInPlace() [8/21]

float& SimTK::clampInPlace ( float  low,
float &  v,
int  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops. Takes an integer bound to avoid need for explicit casts.

◆ clampInPlace() [9/21]

unsigned char& SimTK::clampInPlace ( unsigned char  low,
unsigned char &  v,
unsigned char  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [10/21]

unsigned short& SimTK::clampInPlace ( unsigned short  low,
unsigned short &  v,
unsigned short  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [11/21]

unsigned int& SimTK::clampInPlace ( unsigned int  low,
unsigned int &  v,
unsigned int  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [12/21]

unsigned long& SimTK::clampInPlace ( unsigned long  low,
unsigned long &  v,
unsigned long  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [13/21]

unsigned long long& SimTK::clampInPlace ( unsigned long long  low,
unsigned long long &  v,
unsigned long long  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [14/21]

char& SimTK::clampInPlace ( char  low,
char &  v,
char  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [15/21]

signed char& SimTK::clampInPlace ( signed char  low,
signed char &  v,
signed char  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [16/21]

short& SimTK::clampInPlace ( short  low,
short &  v,
short  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [17/21]

int& SimTK::clampInPlace ( int  low,
int &  v,
int  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [18/21]

long& SimTK::clampInPlace ( long  low,
long &  v,
long  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [19/21]

long long& SimTK::clampInPlace ( long long  low,
long long &  v,
long long  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [20/21]

negator<float>& SimTK::clampInPlace ( float  low,
negator< float > &  v,
float  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clampInPlace() [21/21]

negator<double>& SimTK::clampInPlace ( double  low,
negator< double > &  v,
double  high 
)
inline

Check that low <= v <= high and modify v in place if necessary to bring it into that range.

Parameters
[in]lowThe lower bound; must be <= high.
[in,out]vThe variable whose value is changed if necessary.
[in]highThe upper bound; must be >= low.
Returns
A writable reference to the now-possibly-modified input variable v.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Cost: These are very fast inline methods; the floating point ones use just two flops.

◆ clamp() [1/21]

double SimTK::clamp ( double  low,
double  v,
double  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [2/21]

float SimTK::clamp ( float  low,
float  v,
float  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [3/21]

double SimTK::clamp ( int  low,
double  v,
int  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace() Takes integer bounds to avoid need for explicit casts.

◆ clamp() [4/21]

float SimTK::clamp ( int  low,
float  v,
int  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace() Takes integer bounds to avoid need for explicit casts.

◆ clamp() [5/21]

double SimTK::clamp ( int  low,
double  v,
double  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace() Takes an integer bound to avoid need for explicit casts.

◆ clamp() [6/21]

float SimTK::clamp ( int  low,
float  v,
float  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace() Takes an integer bound to avoid need for explicit casts.

◆ clamp() [7/21]

double SimTK::clamp ( double  low,
double  v,
int  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace() Takes an integer bound to avoid need for explicit casts.

◆ clamp() [8/21]

float SimTK::clamp ( float  low,
float  v,
int  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace() Takes an integer bound to avoid need for explicit casts.

◆ clamp() [9/21]

unsigned char SimTK::clamp ( unsigned char  low,
unsigned char  v,
unsigned char  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [10/21]

unsigned short SimTK::clamp ( unsigned short  low,
unsigned short  v,
unsigned short  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [11/21]

unsigned int SimTK::clamp ( unsigned int  low,
unsigned int  v,
unsigned int  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [12/21]

unsigned long SimTK::clamp ( unsigned long  low,
unsigned long  v,
unsigned long  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [13/21]

unsigned long long SimTK::clamp ( unsigned long long  low,
unsigned long long  v,
unsigned long long  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [14/21]

char SimTK::clamp ( char  low,
char  v,
char  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [15/21]

signed char SimTK::clamp ( signed char  low,
signed char  v,
signed char  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [16/21]

short SimTK::clamp ( short  low,
short  v,
short  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [17/21]

int SimTK::clamp ( int  low,
int  v,
int  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [18/21]

long SimTK::clamp ( long  low,
long  v,
long  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [19/21]

long long SimTK::clamp ( long long  low,
long long  v,
long long  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace()

◆ clamp() [20/21]

float SimTK::clamp ( float  low,
negator< float >  v,
float  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace() Explicitly takes a negator<float> argument to help the compiler find the right overload, but the negation is performed (1 extra flop) and the result type is an ordinary float.

◆ clamp() [21/21]

double SimTK::clamp ( double  low,
negator< double >  v,
double  high 
)
inline

If v is in range low <= v <= high then return v, otherwise return the nearest bound; this function does not modify the input variable v.

Parameters
[in]lowThe lower bound; must be <= high.
[in]vThe value to be put into range [low,high].
[in]highThe upper bound; must be >= low.
Returns
Either the value v or one of the bounds.

This method is overloaded for all standard integral and floating point types. All the arguments and the return type will be the same type; there are no explicit overloads for mixed types so you may find you need to cast the bounds in some cases to ensure you are calling the correct overload.

Warning
Viewed as a function of the input value v, clamp(v) is not very smooth – it is continuous (C0) but even its first derivative is infinite at the bounds.

Cost: These are very fast, inline methods; the floating point ones use just two flops.

See also
clampInPlace() Explicitly takes a negator<double> argument to help the compiler find the right overload, but the negation is performed (1 extra flop) and the result type is an ordinary double.