Re: [Help] Math Error?

From: Chris Jacobson (fear@ATHENET.NET)
Date: 04/12/98


On 4/12/98 4:03 PM, Akuma/Chris Baggett/DOOMer (doomer18@EARTHLINK.NET)
stated:

>int top_of_dam_messt = 18;
>int perc_hit = 6;
>
>  msgnum = (int)(((perc_hit)/(top_of_dam_messt + 1)) + 0.5);

This is because ints drop decimals, regardless.
For example:

(value / max) will always be 0, since VALUE is less than Max.
(value / max) * 100, for calculating a percentage, will always be 0 also,
because 0 * 100 = 0.

The proper method for determining a percentage value is:
(value * 100) / max = %

So, applying basic substition algebra (substition?  I think that is the
property being used :-), assuming you have the percentage, and want to
find what the index would be:

(percentage * max) / 100 = index

6 * 18 = 108
108 / 100 = 1.08 (drops .08)

So if you have 100%, it is:  1800 / 100 = 18
50 * 18 = 900
900 / 100 = 9

Subtract 1, and you have the index from your dam_message table.  If the
table is the count, rather than the index of the top entry (which is not
the standard circle method), use (top - 1)

This formula was reached in the following manner:

(value / max) * 100 = percent
percent / 100 = value / max
percent / 100 * max = value
percent * max / 100 = value    (remember, order of applying divisions and
multiplications is unimportant when only divs/mults are present!  This
order also preserves divisions for a later time, when values will be
largest and risk of dropping decimals is lowest, and least important).

- Chris Jacobson


     +------------------------------------------------------------+
     | 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