Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/04/12 11:24:29 (12 years ago)
Author:
gkronber
Message:

#1890

  • added an extension to calculate the range of IEnumerable<double>
  • increased the buffer size for the heuristic determination of separator characters in the table file parser (to make it work with files that have more than 1024 bytes in the second line).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/EnumerableStatisticExtensions.cs

    r8531 r8564  
    4545        return (valuesArr[(n / 2) - 1] + valuesArr[n / 2]) / 2.0;
    4646      }
     47    }
     48
     49    /// <summary>
     50    /// Calculates the range (max - min) of the enumeration.
     51    /// </summary>
     52    /// <param name="values"></param>
     53    /// <returns></returns>
     54    public static double Range(this IEnumerable<double> values) {
     55      double min = double.PositiveInfinity;
     56      double max = double.NegativeInfinity;
     57      int i = 0;
     58      foreach (var e in values) {
     59        if (min > e) min = e;
     60        if (max < e) max = e;
     61        i++;
     62      }
     63      if (i <= 2) throw new ArgumentException("The enumerable must contain at least two elements", "values");
     64      return max - min;
    4765    }
    4866
Note: See TracChangeset for help on using the changeset viewer.