clamp(), clampInPlace()
[Scalar Functions]

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

Functions

double & 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.
float & clampInPlace (float low, float &v, float high)
long double & clampInPlace (long double low, long double &v, long double high)
double & clampInPlace (int low, double &v, int high)
float & clampInPlace (int low, float &v, int high)
long double & clampInPlace (int low, long double &v, int high)
double & clampInPlace (int low, double &v, double high)
float & clampInPlace (int low, float &v, float high)
long double & clampInPlace (int low, long double &v, long double high)
double & clampInPlace (double low, double &v, int high)
float & clampInPlace (float low, float &v, int high)
long double & clampInPlace (long double low, long double &v, int high)
unsigned char & clampInPlace (unsigned char low, unsigned char &v, unsigned char high)
unsigned short & clampInPlace (unsigned short low, unsigned short &v, unsigned short high)
unsigned int & clampInPlace (unsigned int low, unsigned int &v, unsigned int high)
unsigned long & clampInPlace (unsigned long low, unsigned long &v, unsigned long high)
unsigned long long & clampInPlace (unsigned long long low, unsigned long long &v, unsigned long long high)
char & clampInPlace (char low, char &v, char high)
signed char & clampInPlace (signed char low, signed char &v, signed char high)
short & clampInPlace (short low, short &v, short high)
int & clampInPlace (int low, int &v, int high)
long & clampInPlace (long low, long &v, long high)
long long & clampInPlace (long long low, long long &v, long long high)
negator< float > & clampInPlace (float low, negator< float > &v, float high)
negator< double > & clampInPlace (double low, negator< double > &v, double high)
negator< long double > & clampInPlace (long double low, negator< long double > &v, long double high)
double 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.
float clamp (float low, float v, float high)
long double clamp (long double low, long double v, long double high)
double clamp (int low, double v, int high)
float clamp (int low, float v, int high)
long double clamp (int low, long double v, int high)
double clamp (int low, double v, double high)
float clamp (int low, float v, float high)
long double clamp (int low, long double v, long double high)
double clamp (double low, double v, int high)
float clamp (float low, float v, int high)
long double clamp (long double low, long double v, int high)
unsigned char clamp (unsigned char low, unsigned char v, unsigned char high)
unsigned short clamp (unsigned short low, unsigned short v, unsigned short high)
unsigned int clamp (unsigned int low, unsigned int v, unsigned int high)
unsigned long clamp (unsigned long low, unsigned long v, unsigned long high)
unsigned long long clamp (unsigned long long low, unsigned long long v, unsigned long long high)
char clamp (char low, char v, char high)
signed char clamp (signed char low, signed char v, signed char high)
short clamp (short low, short v, short high)
int clamp (int low, int v, int high)
long clamp (long low, long v, long high)
long long clamp (long long low, long long v, long long high)
float clamp (float low, negator< float > v, float high)
double clamp (double low, negator< double > v, double high)
long double clamp (long double low, negator< long double > v, long double high)

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 [los,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

long double SimTK::clamp ( long double  low,
negator< long double >  v,
long 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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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<long 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 long double.

References SimTK::clamp().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clamp().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clamp().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

long double SimTK::clamp ( long double  low,
long 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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

long double SimTK::clamp ( int  low,
long double  v,
long 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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

long double SimTK::clamp ( int  low,
long 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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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.

References SimTK::clampInPlace().

long double SimTK::clamp ( long double  low,
long double  v,
long 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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in] v The value to be put into range [low,high].
[in] high The 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()

References SimTK::clampInPlace().

Referenced by SimTK::clamp().

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

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

Parameters:
[in] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

long double& SimTK::clampInPlace ( long double  low,
long 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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

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

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

Parameters:
[in] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

long double& SimTK::clampInPlace ( int  low,
long 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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

References SimTK::clampInPlace().

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

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

Parameters:
[in] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

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] low The lower bound; must be <= high.
[in,out] v The variable whose value is changed if necessary.
[in] high The 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.

Referenced by SimTK::clamp(), SimTK::clampInPlace(), SimTK::d2stepAny(), SimTK::d3stepAny(), SimTK::dstepAny(), and SimTK::stepAny().


Generated on Thu Aug 12 16:37:48 2010 for SimTKcore by  doxygen 1.6.1