A
A
ahame2020-12-18 21:03:07
C++ / C#
ahame, 2020-12-18 21:03:07

How to fix this divide-by-zero error?

This division may result in a division by zero error because the value 0 is leaking as a possible divisor.
We are talking about lines 1 and 15

int n = 0;
  double val = 0;

  for (int i = 0; i < p_count; ++i) {
    std::vector<double> cpoint;
    for (unsigned int j = 0; j < dim; ++j) {
      cpoint.push_back(p[dim * i + j]);
    }
    if (parea(cpoint)) {
      n++;
      val += pfunction(cpoint);
    }
  }

  val = val / n;
  double area = std::pow(sd, dim) * n / p_count;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petryaev, 2020-12-18
@Gremlin92

You have n==0 when p_count==0 or dim==0 or parea never works. Need more information on the code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question