Mercurial > urweb
diff lib/js/urweb.js @ 1619:15e0c935c91b
Catching integer divisions by zero
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sat, 03 Dec 2011 09:44:07 -0500 |
parents | 7d459f223ac2 |
children | 43f22a8f76cc |
line wrap: on
line diff
--- a/lib/js/urweb.js Wed Nov 30 15:28:56 2011 -0500 +++ b/lib/js/urweb.js Sat Dec 03 09:44:07 2011 -0500 @@ -19,9 +19,9 @@ function minus(x, y) { return x - y; } function times(x, y) { return x * y; } function div(x, y) { return x / y; } -function divInt(x, y) { var n = x / y; return n < 0 ? Math.ceil(n) : Math.floor(n); } +function divInt(x, y) { if (y == 0) er("Division by zero"); var n = x / y; return n < 0 ? Math.ceil(n) : Math.floor(n); } function mod(x, y) { return x % y; } -function modInt(x, y) { var n = x % y; return n < 0 ? Math.ceil(n) : Math.floor(n); } +function modInt(x, y) { if (y == 0) er("Division by zero"); var n = x % y; return n < 0 ? Math.ceil(n) : Math.floor(n); } function lt(x, y) { return x < y; } function le(x, y) { return x <= y; }