Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Division and fractions.

Division and fractions.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Eleander   Poland  (3 posts)  Bio
Date Sat 14 Dec 2002 10:15 PM (UTC)
Message
I need to divide a few numbers to obtain a fraction number. I tried to do this on float, double, long double, but it doesn't work, smaug is rounding the number to the integer. Nevertheless when I use sqrt, it doesn't round the result.
It seems weird to me, and i would be very grateful if anyone could tell me what to do.
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #1 on Mon 16 Dec 2002 01:25 AM (UTC)
Message
I believe this has to do with how the division functions are generally written for MU*s in general, multiplication as well. The vast majority of all functions are designed to round in order to avoid fractional results in combat and similar situations since its just completely unrealistic to code a completely seperate group of math functions to handle specific spell and combat related calculations. Square roots probably didn't get included in the rounding functions because nobody ever actually expected sqrts to be used on a mud.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Eleander   Poland  (3 posts)  Bio
Date Reply #2 on Thu 19 Dec 2002 02:09 PM (UTC)
Message
Okay but how can I solve the problem ? What should I seek ? I would be grateful for giving me some direction, even if you don't know the answer.
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #3 on Sat 21 Dec 2002 01:31 AM (UTC)
Message
Unfortunately, I suspect this would require outright recoding a vast majority of everything in your src that deals with xp, weapon damage, spell damage, coin splitting and anything else dealing with potentially fractional amounts that can't be processed properly as fractions. Having pointed that out, I quite simply have no idea where to even begin looking into such a thing but if I had to guess I'd start looking in the nanny file. I've never actually needed decimals for anything in a mud so I've never been curious enough to go hunting for this. I would also recommend getting the earlist version of pure rom or merc you can find as that would have the least extra code to sift thru to find your math functions to handle decimal rounding.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #4 on Sun 22 Dec 2002 11:15 AM (UTC)

Amended on Sun 22 Dec 2002 11:25 AM (UTC) by Meerclar

Message
Ok, so even I'm wrong once in a while. In this case, the problem rests with how division is handled by C and C++.

Unless otherwise noted, division is assumed to be integer values only and only integer results are returned. To change that, try using


(num_type) result = (num_type) number_1 / (num_type) number_2


If that fails you can at least retrieve the remainder by using


remainder = number_1 % number_2


(num_type) == int, long, float, etc

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Eleander   Poland  (3 posts)  Bio
Date Reply #5 on Sun 22 Dec 2002 03:34 PM (UTC)
Message
I've used cast operator and it's working well. Thank you very much i've realy needed that.
--sorry for possible misspeling--
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


17,268 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.