Rounding Numbers / Damage Dealing
Author | Topic: Rounding Numbers / Damage Dealing |
---|---|
BANNED
Member # 4
|
written Monday, July 19 2004 09:59
Profile
Homepage
How does one round numbers? For instance, a value divided by two. And if that's impossible, can damage be dealt in increments of .5? (EDIT again: Hah! I found a use for this topic after all. ^_^) [ Monday, July 19, 2004 10:55: Message edited by: Sathoj ] -------------------- * Posts: 6936 | Registered: Tuesday, September 18 2001 07:00 |
Shock Trooper
Member # 4180
|
written Monday, July 19 2004 11:10
Profile
(untested pseudo-code) -------------------- -spyderbytes Posts: 200 | Registered: Wednesday, March 31 2004 08:00 |
Off With Their Heads
Member # 4045
|
written Monday, July 19 2004 11:25
Profile
Homepage
I believe decimals get rounded down. BoA just cuts off the part after the decimal point. I think I tried this once and it printed Debug value: 4 Debug value: 4 It's true! -------------------- Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens. Smoo: Get ready to face the walls! Ephesos: In conclusion, yarr. Kelandon's Pink and Pretty Page!!: the authorized location for all things by me The Archive of all released BoE scenarios ever Posts: 7968 | Registered: Saturday, February 28 2004 08:00 |
Shock Trooper
Member # 4180
|
written Monday, July 19 2004 12:15
Profile
quote: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". :) EDIT: That's what I get for posting before my "morning" coffee (I keep odd hours :) ). The pseudo-code should be: Obviously, the remainder won't always be greater than '5', but instead half or more of the divisor. :D [ Monday, July 19, 2004 12:28: Message edited by: spyderbytes ] -------------------- -spyderbytes Posts: 200 | Registered: Wednesday, March 31 2004 08:00 |
Agent
Member # 2820
|
written Tuesday, July 20 2004 07:01
Profile
Uhhh, wouldn't it be easier just to do this: 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. [ Tuesday, July 20, 2004 07:04: Message edited by: Keep ] -------------------- Thuryl: I mean, most of us don't go around consuming our own bodily fluids, no matter how delicious they are. ==== Alorael: War and violence would end if we all had each other's babies! ==== Drakefyre: Those are hideous mangos. Posts: 1415 | Registered: Thursday, March 27 2003 08:00 |
Shock Trooper
Member # 4180
|
written Tuesday, July 20 2004 11:44
Profile
Not sure why that would be easier. :) 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 :) ). 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: 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. :D -------------------- -spyderbytes Posts: 200 | Registered: Wednesday, March 31 2004 08:00 |