safeDivide method

double safeDivide(
  1. num b, {
  2. num whenBothZero = 0,
  3. num whenDivByZero = double.infinity,
  4. bool returnNaNOnDivByZero = false,
})

Safely divides two numbers with custom handling for division by zero and zero values.

  • Returns whenBothZero if both this and b are zero.
  • Returns whenDivByZero if dividing by zero unless returnNaNOnDivByZero is true.
  • Otherwise, returns this / b.

Implementation

double safeDivide(
  num b, {
  num whenBothZero = 0,
  num whenDivByZero = double.infinity,
  bool returnNaNOnDivByZero = false,
}) =>
    NumbersHelper.safeDivide(
      this,
      b,
      whenDivByZero: whenDivByZero,
      whenBothZero: whenBothZero,
      returnNaNOnDivByZero: returnNaNOnDivByZero,
    );