summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-math
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-03-28 14:02:30 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-03-28 23:22:32 +0900
commit3b92b642eb3f7e3ed1b68bda86d073d310c5d131 (patch)
tree057e13a0163b76089dccefea9d695e31ccc6fd56 /mrbgems/mruby-math
parenta26856f88313679c24ec7f9f098082e0949f9d44 (diff)
downloadmruby-3b92b642eb3f7e3ed1b68bda86d073d310c5d131.tar.gz
mruby-3b92b642eb3f7e3ed1b68bda86d073d310c5d131.zip
Break loop whem `sum==0` to avoid zero division; ref #4345
Diffstat (limited to 'mrbgems/mruby-math')
-rw-r--r--mrbgems/mruby-math/src/math.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c
index 39fed6cd3..ef0dc1857 100644
--- a/mrbgems/mruby-math/src/math.c
+++ b/mrbgems/mruby-math/src/math.c
@@ -120,6 +120,7 @@ erf(double x)
term *= xsqr/j;
sum += term/(2*j+1);
++j;
+ if (sum == 0) break;
} while (fabs(term/sum) > DBL_EPSILON);
return two_sqrtpi*sum;
}