|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Sep 18, 2008 12:41 pm
Division and Percentage |
How can you divide for example 5/10? The result keeps coming up as 0 when it should be 0.5.
|
|
|
|
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Thu Sep 18, 2008 12:45 pm |
Wow, that's weird. I just tried it in untitled session with both %float and without and it indeed returned 0.
Bug? |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Sep 18, 2008 12:59 pm |
I tried everything too. It won't let you divide in this manner with variables or numbers directly.
$a=6
$b=25
$result=$a/$b doesn't work.
6/25 doesn't work.
The result should be 0.24. I was trying to divide the numbers then multiply by 100 to get percent. If $a is larger than $b then it divides fine however. |
|
|
|
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Thu Sep 18, 2008 1:03 pm |
It seems like something is messed up with results which outcome contains a floating point.
I suck at math so hopefully I got the terms correctly
Hopefully Zugg can share some light on what might be happening here. Looks like we've tested so far as we could ourselves. |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Sep 18, 2008 1:52 pm |
There is no bug in this. You may just not be inputting the correct syntax.
#SAY (%float(6)/25)
returns
0.24
#SAY (%float(6)/%float(25))
returns
0.24
You've always needed %float to return decimal numbers.
Charneus |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Sep 18, 2008 2:27 pm |
I never said there was a bug. I asked how you do it to make it work.
|
|
|
|
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Thu Sep 18, 2008 3:11 pm |
Now I'm going to argue semantics, but shouldn't %float(%eval(5/10)) work just as well as when you'd
do %eval(%float(5)/%float(10))?
To be honest, the latter seems pretty ugly to begin with. |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Sep 18, 2008 3:34 pm |
oldguy2, I was referring to Prog's question of "Bug?"
Prog, semantics is fun to argue! Anyway, it does seem to reason that your example should work, but what's happening is that it is evaluating 5/10 before determining to make it a floating point. It's like math. You do everything in parentheses first, then exponents and so forth. When parentheses contain parentheses, you do the inside parentheses first, then expand that out to the outer parentheses. Therefore:
(6+(5*10)) will return 56 instead of 110 because it has to do the (5*10) first. Hope this makes sense.
Charneus |
|
|
|
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Thu Sep 18, 2008 3:45 pm |
Well, as I said the very first time, I suck at math. So what I'm going to do is take the above as a fact and move on.
Because in my mind, which isn't really touched by the math god, my initial suggestion should've worked, too
Anyway, it's good to know the way and the explanation once I have to do calculations like that in CMud myself. |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Sep 18, 2008 4:50 pm |
The problem is that in your first example you are doing integer division. If both the numberator and denominators are integers, Cmud will do integer division, which rounds down to the nearest whole number. To do the division you want, try: 5/10.0
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: Thu Sep 18, 2008 8:12 pm |
have you tried adding the .0? then it will know they are float and use float math instead of integer math
i believe you need (5.0/10.0) |
|
_________________ Discord: Shalimarwildcat |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Sep 18, 2008 8:18 pm |
Yeah it works fine. That's all I needed. Thanks.
|
|
|
|
|
|