3 ms·
> So it should have been `(new_maxhp * old_hp) / old_maxhp`. I don't see how that couldn't run into similar problems. I would use `clamp(old_hp * (new_maxhp /
by layer8 4y ago
> So it should have been `(new_maxhp * old_hp) / old_maxhp`.
I don't see how that couldn't run into similar problems. I would use `clamp(old_hp * (new_maxhp / old_maxhp), 1, new_maxhp)` (assuming that old_hp >= 1).
- iforgotpassword 4y agoIt could, but only at very large values. It's at least the much more robust solution.
- tpolzer 4y agoIf you assume that all three numbers are small integers, doing the division last minimizes precision loss (and doesn't have any loss if the accurate result is representable as a float). Otherwise you get loss from the division and then multiply that loss (by >1).