slice method Null safety

ContinuousDistribution slice(
  1. {double min = double.negativeInfinity,
  2. double max = double.infinity,
  3. int? attempts}
)

Returns a slice of the distribution.

Parameter attempts is a hint for the number of iterations in rejection sampling. The default value is unspecified.

Example

import 'package:calc/calc.dart';

void main() {
  final normalDistribution = NormalDistribution(0.0, 1.0);
  final allPositiveNormalDistribution = distribution.slice(min:0.0);
}

Implementation

ContinuousDistribution slice({
  double min = double.negativeInfinity,
  double max = double.infinity,
  int? attempts,
}) {
  if (min.isNaN || min > max) {
    throw ArgumentError.value(min, 'min');
  }
  if (max.isNaN) {
    throw ArgumentError.value(max, 'max');
  }
  if (min == double.negativeInfinity && max == double.infinity) {
    return this;
  }
  return _SlicedContinuousDistribution(this, min, max, attempts ?? 100);
}