Flexible routine to range a number into a given range between a lower and an higher bound.

Namespace: ASCOM.Astrometry.AstroUtils
Assembly: ASCOM.Astrometry (in ASCOM.Astrometry.dll) Version: 6.0.0.0 (6.1.1.2619)

Syntax

C#
public double Range(
	double Value,
	double LowerBound,
	bool LowerEqual,
	double UpperBound,
	bool UpperEqual
)
Visual Basic
Public Function Range ( _
	Value As Double, _
	LowerBound As Double, _
	LowerEqual As Boolean, _
	UpperBound As Double, _
	UpperEqual As Boolean _
) As Double
Visual C++
public:
virtual double Range(
	double Value, 
	double LowerBound, 
	bool LowerEqual, 
	double UpperBound, 
	bool UpperEqual
) sealed

Parameters

Value
Type: System..::..Double
Value to be ranged
LowerBound
Type: System..::..Double
Lowest value of the range
LowerEqual
Type: System..::..Boolean
Boolean flag indicating whether the ranged value can have the lower bound value
UpperBound
Type: System..::..Double
Highest value of the range
UpperEqual
Type: System..::..Boolean
Boolean flag indicating whether the ranged value can have the upper bound value

Return Value

The ranged nunmber as a double

Remarks

UpperEqual and LowerEqual switches control whether the ranged value can be equal to either the upper and lower bounds. So, to range an hour angle into the range 0 to 23.999999.. hours, use this call:
CopyVB.NET
RangedValue = Range(InputValue, 0.0, True, 24.0, False)

The input value will be returned in the range where 0.0 is an allowable value and 24.0 is not i.e. in the range 0..23.999999..

It is not permissible for both LowerEqual and UpperEqual to be false because it will not be possible to return a value that is exactly equal to either lower or upper bounds. An exception is thrown if this scenario is requested.

Exceptions

ExceptionCondition
ASCOM..::..InvalidValueExceptionThrown if the lower bound is greater than the upper bound.
ASCOM..::..InvalidValueExceptionThrown if LowerEqual and UpperEqual are both false and the ranged value equals one of these values. This is impossible to handle as the algorithm will always violate one of the rules!

See Also