normalPdf function

num normalPdf(
  1. num x,
  2. num mean,
  3. num stdDev
)

Normal probability density function.

Throws an error of type ErrorOfType<InvalidFunctionParameter> if stdDev < 0.

Implementation

num normalPdf(num x, num mean, num stdDev) {
  if (stdDev <= 0.0) {
    throw throw ErrorOfType<InvalidFunctionParameter>(
      invalidState: 'stdDev: $stdDev <= 0.',
      expectedState: 'stdDev > 0',
    );
  }
  final invStdDev = 1.0 / stdDev;
  x = (x - mean) * invStdDev;
  return invSqrt2Pi * invStdDev * math.exp(-0.5 * x * x);
}