Jump to content

Rounding Numbers / Damage Dealing


Recommended Posts

Quote:
Originally written by Just call me Kel:
I believe decimals get rounded down. BoA just cuts off the part after the decimal point.
Right. That's why if the remainder (x modulo y returns the remainder from integer division) is more than 5 (which means more than .5), you can just do the integer div and add 1 to "round up". smile

EDIT: That's what I get for posting before my "morning" coffee (I keep odd hours smile ). The pseudo-code should be:

Code:
if ((x % y) >= (y / 2))  x = (x / y) + 1;else  x = x / y;
Obviously, the remainder won't always be greater than '5', but instead half or more of the divisor. laugh
Link to comment
Share on other sites

Uhhh, wouldn't it be easier just to do this:

 

Code:
y = y * 10;if ((y / 2) % 10 == 5)[odd]else[even]
EDIT: I believe this is the same behavior as C and Java, isn't it? When you declare int variables and divide, it just chops off the stuff after the decimal point.

 

I think this because I vaguely remember doing 5/2=2 in Java.

Link to comment
Share on other sites

Not sure why that would be easier. smile

 

The pseudo-code I came up with once I finally pulled my head out of the dark cavity it was in has the advantage of being able to round up regardless of the divisor (and yes, the original post did mention "like dividing by 2", but bulletproof is always better smile ).

 

Also, seems to me that if all you're trying to determine is what's even and what's odd, it would be easier to just:

 

Code:
if ((x % 2) == 0)  ...I'm even...else  ...I'm odd...
Guess I just missed the point of multiplying by 10 then dividing by 2 and checking for a 5 remainder modulo 10... but it's pre-coffee time for me again. laugh
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...