Class NumericRangeTools
- Namespace
- Plugin.BaseTypeExtensions
- Assembly
- Plugin.BaseTypeExtensions.dll
Provides utility methods for numeric range conversions, percentage calculations, and value mapping operations.
public static class NumericRangeTools
- Inheritance
-
NumericRangeTools
- Inherited Members
Remarks
This class contains helper methods for converting between absolute and relative values, percentage calculations, and generating numeric ranges. All methods are optimized for performance and support generic numeric types where applicable.
Methods
GetRange(DateTime, DateTime, TimeSpan)
Generates a sequence of DateTime values from start to end with a specified step.
public static IEnumerable<DateTime> GetRange(DateTime start, DateTime end, TimeSpan step)
Parameters
startDateTimeThe start of the range.
endDateTimeThe end of the range.
stepTimeSpanThe step size between each DateTime in the range.
Returns
- IEnumerable<DateTime>
An IEnumerable of DateTime values representing the range.
Remarks
This method generates a sequence of DateTime values starting from start and stopping before end, using the magnitude of
step to move between values. If step is zero or equals MinValue, an empty sequence is returned.
GetRange(double, double, double)
Generates a sequence of numbers from start to end with a specified step.
public static IEnumerable<double> GetRange(double start, double end, double step)
Parameters
startdoubleThe start of the range.
enddoubleThe end of the range.
stepdoubleThe step size between each number in the range.
Returns
- IEnumerable<double>
An IEnumerable of double values representing the range.
Remarks
This method generates a sequence of numbers starting from start and stopping before end, using the magnitude of
step to move between values. If step is zero, NaN, or infinite, an empty sequence is returned.
GetRange(float, float, float)
Generates a sequence of floating-point numbers from start to end with a specified step.
public static IEnumerable<float> GetRange(float start, float end, float step)
Parameters
startfloatThe start of the range.
endfloatThe end of the range.
stepfloatThe step size between each number in the range.
Returns
- IEnumerable<float>
An IEnumerable of float values representing the range.
Remarks
This method generates a sequence of floating-point numbers starting from start and stopping before end, using the magnitude of
step to move between values. If step is zero, NaN, or infinite, an empty sequence is returned.
GetRange<T>(T, T, T)
Generates a sequence of numbers from start to end with a specified step.
public static IEnumerable<T> GetRange<T>(T start, T end, T step) where T : INumber<T>
Parameters
startTThe start of the range.
endTThe end of the range.
stepTThe step size between each number in the range.
Returns
- IEnumerable<T>
An IEnumerable of T values representing the range.
Type Parameters
TThe numeric type that implements INumber<T>.
Remarks
This method generates a sequence of numbers starting from start to end, inclusive, with the specified step.
If step is zero, an empty sequence is returned.
The sequence will include both start and end if they are reachable with the given step.