uniformPdf function

num uniformPdf(
  1. num x,
  2. num min,
  3. num max
)

Uniform probability density function with non-zero support over the interval (min, max).

Throws an exception of type ErrorOfType<InvalidFunctionParameter> if min >= max.

Implementation

num uniformPdf(num x, num min, num max) {
  if (min >= max) {
    throw ErrorOfType<InvalidFunctionParameter>(
      invalidState: 'min: $min >= max: $max',
      expectedState: 'min < max',
    );
  }
  return (x < min || x > max) ? 0.0 : 1.0 / (max - min);
}