From 7136358c17f8193173e8a0a9469821039212d879 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 3 Dec 2011 09:44:07 -0500 Subject: Catching integer divisions by zero --- lib/js/urweb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/js') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index d7bb7b6f..f05957a0 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -19,9 +19,9 @@ function plus(x, y) { return x + y; } 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; } -- cgit v1.2.3