From 675956fb789670ab751ea1ce3e4dfafb155a2950 Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Fri, 24 Feb 2017 03:03:45 +0100 Subject: [PATCH] my better shot at float comparisons --- qcsrc/common/mutators/mutator/damagetext/damagetext.qc | 4 ++-- qcsrc/lib/math.qh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qcsrc/common/mutators/mutator/damagetext/damagetext.qc b/qcsrc/common/mutators/mutator/damagetext/damagetext.qc index 7fd53f874..686079b4c 100644 --- a/qcsrc/common/mutators/mutator/damagetext/damagetext.qc +++ b/qcsrc/common/mutators/mutator/damagetext/damagetext.qc @@ -104,7 +104,7 @@ CLASS(DamageText, Object) int potential = rint(this.m_potential_damage / DAMAGETEXT_PRECISION_MULTIPLIER); int potential_health = rint((this.m_potential_damage - this.m_armordamage) / DAMAGETEXT_PRECISION_MULTIPLIER); - bool redundant = almost_equals_eps(this.m_healthdamage + this.m_armordamage, this.m_potential_damage, 10); + bool redundant = almost_equals_eps(this.m_healthdamage + this.m_armordamage, this.m_potential_damage, 5); string s = autocvar_cl_damagetext_format; s = strreplace("{armor}", ( @@ -203,7 +203,7 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) { if (armor >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_ARMOR; if (potential_damage >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_POTENTIAL; if (!armor) flags |= DTFLAG_NO_ARMOR; - if (almost_equals_eps(armor + health, potential_damage, 10)) flags |= DTFLAG_NO_POTENTIAL; + if (almost_equals_eps(armor + health, potential_damage, 5)) flags |= DTFLAG_NO_POTENTIAL; msg_entity = it; WriteHeader(MSG_ONE, damagetext); diff --git a/qcsrc/lib/math.qh b/qcsrc/lib/math.qh index f314afad5..94cdcc671 100644 --- a/qcsrc/lib/math.qh +++ b/qcsrc/lib/math.qh @@ -180,7 +180,7 @@ float almost_equals(float a, float b) float almost_equals_eps(float a, float b, float times_eps) { - float eps = (max(a, -a) + max(b, -b)) * FLOAT_EPSILON * times_eps; + float eps = max(fabs(a), fabs(b)) * FLOAT_EPSILON * times_eps; return a - b < eps && b - a < eps; } -- 2.39.2