Re: [CODE] Order of Evaluation and Shorthand Problem

From: Tony Robbins (robbinsw@ucs.orst.edu)
Date: 04/14/00


...

At 04:17 PM 4/14/00 -0700, you wrote:
>I'm having a problem with the order in which a simple expression is being
>evaluated in conjunction with a shorthand assignment operator.
>
>The relevant lines are:
>      (GET_RV(victim, DAM_GEN_INERTIA) = 50;
>      dam = 230;
>      dam *= (GET_RV(victim, DAM_GEN_INERTIA) / 100);
>
>After this line executes, dam = 0.  In actuality, it should equal 115, since
>(by my understanding of the order of evaluation) 50 divided by 100 equals
>1/2.  230 multiplied by 1/2 equals 115.  Yes?
>
>Since the macro GET_RV(victim, DAM_GEN_INTERTIA) positively works and always
>returns the value of 50 in other functions, how can dam be reduced to 0?
>Any ideas or insight is most appreciated.

Order of evaluation isn't your problem; it's how an integer works.
(GET_RV(victim, DAM_GEN_INERTIA) / 100) evaluates to zero, because it
equals 0.5, with the fraction truncated.

A simple way to work it:
dam *= GET_RV(victim, DAM_GEN_INERTIA);
dam /= 100;

This way, damage is multiplied by 50, and then divided by 100.

-Tony

Note:  I hope this is being sent OK, I'm trying Eudora and can't be sure if
it's sending HTML yet.


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



This archive was generated by hypermail 2b30 : 04/10/01 PDT