Double Inclusive Range step by step I've written a method to obtain an IEnumerable from a start point, end point and step. Similar to Enumerable.Range() but for doubles and not fixed step.

public static IEnumerable&lt;double&gt; InclusiveRange(double start, double end, double step = 1)
    {
        while (start &lt;= end)
        {
            yield return start;
            start += step;
        }
    }


Am I missing something, or there is a better approach?
As this is a quit nice approach, it is missing an important part.  

Validation of input parameter  

You should check at least the step parameter if it is a positive number greater 0.  

InclusiveRange(1d, 5d,-1);  


the above call is by your definition a valid call, but can lead to a System.OutOfMemoryException if combined with the .ToList() extension method.  

You need to decide if you want to enable negative step. If you don't want to allow negative values for step a simple guard clause can handle this.  

if (step &lt;= 0) { throw new ArgumentOutOfRangeException("step", "The value has to be greater than 0"); } 


But if you want to enable negative step values you need to add more checks and a different implementation.  

A negative step means that start > end so you would need to introduce 2 more methods which you then call based on step beeing positive or negative.  

private static IEnumerable&lt;double&gt; InclusiveRangeAscending(double start, double end, double step)  
{

}

private static IEnumerable&lt;double&gt; InclusiveRangeDescending(double start, double end, double step)  
{

}  

public static IEnumerable&lt;double&gt; InclusiveRange(double start, double end, double step = 1)
{
    if (step == 0) { throw new ArgumentOutOfRangeException("step", "The value has to be unequal to 0"); }
    if (step &gt; 0)
    {
        return InclusiveRangeAscending(start, end, step);
    }
    else
    {
        return InclusiveRangeDescending(start, end, step);
    }
}