The math in AoE4 is bad and I want to talk about it

The numerical rounding in AoE4 needs to be more clear and consistent…Sometimes we round up, other times we round…sometimes we don’t round at all and just go to the lowest number, regardless of how high the decimal is…or go to the new highest number, regardless of how high the decimal is.

Lets look at an example. Something simple, like Health, so we don’t have to deal with all the hidden variables of something like attack speed or training times.

The Chinese have their Ming Dynasty buff that gives +15% Health. They also get access to Biology, which gives an extra 25% Health.

Lancers have a base Health of 230. So, we have the equation: 230*(1+15/100) = 264.5. In game, it shows that the Base Lancer has 264 in Ming Dynasty. Great! That must mean that we round down on Health!

But, hold on there partner, once we add Biology, we get 230*(1+15/100)*(1+25/100) = 330.62. In game, this shows as 331. So, here we see the first crack in the system. It is standard mathematical convention to round up on .5 or higher and down on anything below .5. Here, we’re using unconventional rules on how to handle .5.

Okay. So, they’re rounding down on .5, instead of up. Big deal. Right? Well…Lets take a look at the humble Scout. A Scout has a base Health of 110. With Biology, the equation would be 110*(1+25/100) = 137.5. Okay. So, we just round down for .5, right? That’s what we do with math in AoE4. Nope! In game, this now rounds UP to 138. Remember our Lancer from earlier? 230*(1+25/100) = 287.5. You guessed it, this also rounds UP to 288 in game.

But, it gets even better! Lets now look at the hardy Spearman. A Hardened Spearman has a base health of 90. Elite Army Tactics increase Health by 15%. Here we go: 90*(1+15/100) = 103.5. This is rounded up to 104 in game. Now, lets upgrade our little guy to a Veteran Spearman, with a base Health of 110. 110*(1+15/100) = 126.5. This also gets rounded up, right? Nope! Even when we have the same unit, getting a bonus from the same source, the game changes the rules on how it handles .5. NOW, we’re rounding DOWN to 126 in game! But, don’t worry, as soon as we upgrade him to Elite, we go right back to rounding UP from 149.5 to 150 in game.

Anyway. This may seem like a small, petty thing. But, I have been trying and banging my head against a project that I’ve been working on as a resource for AoE4 and all this crap tier math makes it an absolute nightmare, because there is no consistency. I can’t just plug numbers into an equation or formula and trust that it will work universally to display accurate stats, because there is always this thing of “Oh, this thing works this way when applied to Unit A, but will work a completely different way when applied to Unit B, with no other factoring variables”. It is quite frustrating and I don’t know if I will ever finish this project because of it.

5 Likes

Agree. I also decided to recalculate all the figures after You and found that with Veteran-Spearmen, the rounding of 0.5 actually disappeared 0.5 hp. Which raises questions. And at the same time, in a similar situation Scout and Lancer, everything is rounded (0.5=1), on the bigger side.

1 Like

Yeah! That’s my major gripe here. I just want consistency. If we want to round down on .5, cool. If we want to just always round down or up, regardless of decimal, also cool. But, how the game math handles decimals should be CONSISTENT across every source. It just needs to always do one, the other or something else. It’s the inconsistency of “Sometimes we do this, but other times we do this other thing” that makes data sourcing a mathematical nightmare.

What I listed here are just a few examples. But, the game is LITTERED with inconsistencies just like these.

1 Like

As far as I’m aware, only the display rounds things in intergers but this is only visual.

The actual numbers aren’t rounded down or up, they are floats containing the full value. A knight with 264.5 health taking 264 damage will stay alive, with the interface showing 1 health.

This becomes evident with resource gathering. If you’re force-dropping 5 resources from a straggler tree for example, you’ll quickly learn how inconsistent that number may be when you turn it in. And it isn’t because there is a mistake in the maths, manually dropping 2 rounds of 5 resources may easily yield 9 resources, because in truth, you’ve picked up 4.x depending on the timing. It’s just because the game operates on floats despite what the UI says.

3 Likes

It’s computer math. Decimal values are represented using floating point arithmetic.

Basically, because of how computers store information they cannot represent a perfect decimal value. When you are identifying that the rounding is off, it’s because the value in binary is actually different.

The decimal number 0.1 is represented in binary as e = −4; s = 110011001100110011001101, which is

0.100000001490116119384765625 exactly.

When you see decimals get funky on computers this is usually the culprit.

That being said, the values shown as a whole number is just aesthetic. The game will use the decimal value, you can have units running around with 0.5 hp

Believe me, undergrad students everywhere share your pain. The math is too smart to be this stupid!

2 Likes

I know I’m joining the conversation late, but the number that appears in the unit data is NOT THE REAL ONE.

Exactly, in fact:

It’s just the “Apparent” number.


APPARENT values VS TRUE values

Actually, when a unit receives HP or attack bonuses with a Percentage (%), this bonus includes the decimals and is retained for future damage calculations.

If an Elite Men-at-Arm in post imperial (IV) with 17 attack gets Elite-Tactics Army actually has 19.55 attack, not 20 (14+6). This can be verified by looking at how much damage it does to other units in several hits:

1 hits → -20 damage (19.55)
2 hits → -39 damage (19.55 x 2 = 39.05)

The appearance of 0 decimals in the HP and attack of units (HP: 200) is only for aesthetics. The damage calculation of HP and ATK actually does include the decimals.

3 Likes