MCPcopy Index your code
hub / github.com/NetHack/NetHack / rounddiv

Function rounddiv

src/hack.c:4550–4572  ·  view source on GitHub ↗

calculate x/y, rounding as appropriate */

Source from the content-addressed store, hash-verified

4548
4549/* calculate x/y, rounding as appropriate */
4550int
4551rounddiv(long x, int y)
4552{
4553 int r, m;
4554 int divsgn = 1;
4555
4556 if (y == 0)
4557 panic("division by zero in rounddiv");
4558 else if (y < 0) {
4559 divsgn = -divsgn;
4560 y = -y;
4561 }
4562 if (x < 0) {
4563 divsgn = -divsgn;
4564 x = -x;
4565 }
4566 r = (int) (x / y);
4567 m = x % y;
4568 if (2 * m >= y)
4569 r++;
4570
4571 return divsgn * r;
4572}
4573
4574
4575/*hack.c*/

Callers 3

newmanFunction · 0.85
doeatFunction · 0.85
monmultiFunction · 0.85

Calls 1

panicFunction · 0.50

Tested by

no test coverage detected