Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
1618:705cb41ac7d0 | 1619:15e0c935c91b |
---|---|
17 function eq(x, y) { return x == y; } | 17 function eq(x, y) { return x == y; } |
18 function plus(x, y) { return x + y; } | 18 function plus(x, y) { return x + y; } |
19 function minus(x, y) { return x - y; } | 19 function minus(x, y) { return x - y; } |
20 function times(x, y) { return x * y; } | 20 function times(x, y) { return x * y; } |
21 function div(x, y) { return x / y; } | 21 function div(x, y) { return x / y; } |
22 function divInt(x, y) { var n = x / y; return n < 0 ? Math.ceil(n) : Math.floor(n); } | 22 function divInt(x, y) { if (y == 0) er("Division by zero"); var n = x / y; return n < 0 ? Math.ceil(n) : Math.floor(n); } |
23 function mod(x, y) { return x % y; } | 23 function mod(x, y) { return x % y; } |
24 function modInt(x, y) { var n = x % y; return n < 0 ? Math.ceil(n) : Math.floor(n); } | 24 function modInt(x, y) { if (y == 0) er("Division by zero"); var n = x % y; return n < 0 ? Math.ceil(n) : Math.floor(n); } |
25 function lt(x, y) { return x < y; } | 25 function lt(x, y) { return x < y; } |
26 function le(x, y) { return x <= y; } | 26 function le(x, y) { return x <= y; } |
27 | 27 |
28 // Characters | 28 // Characters |
29 | 29 |