fcumsumBy<T> function Adding numbers

Float64List fcumsumBy<T>(
  1. Iterable<T> iterable,
  2. num? accessor(
    1. T
    )
)

Returns a full precision cumulative sum of all values yielded by the accessor function applied to each element in the iterable.

fcumsumBy([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1], (d) => d * 2); // [2.0, 2.00000000000002, 2e-14]
cumsumBy([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1], (d) => d * 2); // [2, 2.00000000000002, 1.998e-14]

Although slower, fcumsumBy can replace cumsumBy wherever greater precision is needed. Uses Adder.

This function ignores elements that yield values that do not satisfy any of the following conditions:

  1. The value is not null.
  2. The value is not double.nan.

Useful for filtering and ignoring missing data in datasets.

Implementation

Float64List fcumsumBy<T>(Iterable<T> iterable, num? Function(T) accessor) {
  final adder = Adder(), l = iterable.length, fcumsum = Float64List(l);
  for (var i = 0; i < l; i++) {
    var v = accessor(iterable.elementAt(i));
    fcumsum[i] =
        (adder..add(v != null && !v.isNaN ? v.toDouble() : 0)).valueOf();
  }
  return fcumsum;
}