[Solved] Is something wrong with my damage formula, or am I using the wrong methods?

I want to include a skill that averages the user's current HP% with the target's current HP% and sets both to the midpoint percentage calculated from those values. My formula (final 0 added so there's no additional "damage" from using the skill) is:
c = (a.hp/a.mhp) d = (b.hp/b.mhp) a.hp = a.mhp * ((c+d)/2) b.hp = b.mhp * ((c+d)/2) 0

Which, given values of 20/20 and 10/20, should return:

20 * ((((20/20) + (10/20))/2) = 0.75) = 15
20 * ((((20/20) + (10/20))/2) = 0.75) = 15
But the /2 specifically (which I have to use in order to find the average) causes the game to set the HP to 0, killing both party members instantly even though something like a.hp = a.hp * 0.75 works fine. None of the alternative methods I've tried, like reordering things or using *0.5 instead of /2, work. They either also kill the party instantly or give the incorrect result.

Although I do understand that the application of damage formulas is a little wonky, I don't know how else I can achieve this and it seems very very odd for a computer program to not be able to handle a seemingly simple calculation like this. I'm not the best at math and I've only had VXAce for 3 days, so am I doing something wrong? Could this be done differently/in a better way??
please give us the actual damage formula used - not its better readable multiline description.
depending on how you wrote that it can have different effects, especially if you are using game variables at any point of the calculation (the default game variables can only hold integers, not float variables, unless specifically commanded to do so)
please give us the actual damage formula used - not its better readable multiline description.
Aside from indentation that is pretty much the actual damage formula, since it was too long (when I started trying to implement the formula; it shouldn't be now) and I decided to call it via script. Would it make a difference if I typed it out in the box?

Edit: It seems to make a small difference to type it out in the box (when using * 0.5 instead of /2). Both the script and in-line version either halve the total HP, after which it begins working closer to intended (the script version's result for b.hp is slightly off, but the inline version is correct; I did change the type of the skill in-between though), or, if the user and target start with <100% HP, kills the party instantly, so not ideal. Adding rounding also results in the party being killed instantly in almost the same way using /2 does.
c=(a.hp/a.mhp);d=(b.hp/b.mhp);a.hp=a.mhp*((c+d)*0.5);b.hp=b.mhp*((c+d)*0.5);0

Ruby:
class Game_Battler < Game_BattlerBase
  def equilibrium(a,b)
    c = (a.hp/a.mhp)
    d = (b.hp/b.mhp)
    a.hp = a.mhp * ((c+d)/2)
    b.hp = b.mhp * ((c+d)/2)
    0
  end
end
plug some actual values into the formula as it is, and consider the fact that c and d might be being rounded to 0.

add a ( ).to_f at the end of every parentheses to make the division a float, and save a float to the variable.
otherwise when coming to the second block, you'd be operating with integers less-than-1 values, and less-than-one integer is 0.
plug some actual values into the formula as it is, and consider the fact that c and d might be being rounded to 0.

add a ( ).to_f at the end of every parentheses to make the division a float, and save a float to the variable.
otherwise when coming to the second block, you'd be operating with integers less-than-1 values, and less-than-one integer is 0.
Took a liiittle brute-forcing but this was perfect, thanks so much! I didn't get that integer input would always be dealt with as integer before.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-is-something-wrong-with-my-damage-formula-or-am-i-using-the-wrong-methods.143539/