Skip to content

Commit

Permalink
Raise error when dividing vector by zero (#2605)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeinaJi authored Nov 9, 2023
1 parent c1ac797 commit 9700e91
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ivoc/ivocvect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,11 @@ static Object** v_mul(void* v1) {
static Object** v_div(void* v1) {
Vect* x = (Vect*) v1;
if (hoc_argtype(1) == NUMBER) {
std::for_each(x->begin(), x->end(), [](double& d) { d /= *getarg(1); });
if (*getarg(1) == 0.0) {
hoc_execerror("Vector", "Division by zero");
} else {
std::for_each(x->begin(), x->end(), [](double& d) { d /= *getarg(1); });
}
}
if (hoc_is_object_arg(1)) {
Vect* y = vector_arg(1);
Expand Down

0 comments on commit 9700e91

Please sign in to comment.