namespace SPTarkov.Server.Core.Extensions { public static class MathExtensions { /// /// Helper to create the cumulative sum of all enumerable elements /// [1, 2, 3, 4].CumulativeSum() = [1, 3, 6, 10] /// /// The enumerable with numbers of which to calculate the cumulative sum /// cumulative sum of values public static IEnumerable CumulativeSum(this IEnumerable values) { double sum = 0; foreach (var value in values) { sum += value; yield return sum; } } /// /// Helper to create the cumulative sum of all enumerable elements /// [1, 2, 3, 4].CumulativeSum() = [1, 3, 6, 10] /// /// The enumerable with numbers of which to calculate the cumulative sum /// cumulative sum of values public static IEnumerable CumulativeSum(this IEnumerable values) { float sum = 0; foreach (var value in values) { sum += value; yield return sum; } } /// /// Helper to create the product of each element times factor /// /// The enumerable of numbers which shall be multiplied by the factor /// Number to multiply each element by /// An enumerable of elements all multiplied by the factor public static IEnumerable Product(this IEnumerable values, double factor) { return values.Select(v => v * factor); } /// /// Helper to create the product of each element times factor /// /// The enumerable of numbers which shall be multiplied by the factor /// Number to multiply each element by /// An enumerable of elements all multiplied by the factor public static IEnumerable Product(this IEnumerable values, float factor) { return values.Select(v => v * factor); } } }