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
start
DateTimeThe start of the range.
end
DateTimeThe end of the range.
step
TimeSpanThe 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
start
doubleThe start of the range.
end
doubleThe end of the range.
step
doubleThe 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
start
floatThe start of the range.
end
floatThe end of the range.
step
floatThe 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
start
TThe start of the range.
end
TThe end of the range.
step
TThe step size between each number in the range.
Returns
- IEnumerable<T>
An IEnumerable of T values representing the range.
Type Parameters
T
The 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.