Re: [Help] Math Error?

From: James T Browning (jbrownin@LCSC.EDU)
Date: 04/12/98


At 04:03 PM 4/12/98 -0500, Akuma wrote:
>I realize that this is not really too CircleMUD related,
>but would someone mind helping me out with this problem.
>
>Given:
>int top_of_dam_messt = 18;
>int perc_hit = 6;
>
>  msgnum = (int)(((perc_hit)/(top_of_dam_messt + 1)) + 0.5);
>
>Why does msgnum keep coming out to Zero (0)?
>
>I'd appreciate some help on this.  I'm trying to make
>damage messages load from a file much like fight messages do
>so that I can reboot them from the mud.
>
>I'd appreciate any help on this.
>
::lots of stuff chopped::

alright assuming fp math at all steps w/ truncation/ rounading at the last...

(6/(18+1))+.5
6/19+.5= 31/38
or 1 rounded or 0 truncated

if you assume integer math at all step (more likely)
6/19=0
+.5=0

to test set perc_hit to any value 9.5 or above


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST