Author: alarantalara
Date: Mon Mar 26 07:01:16 2012
New Revision: 53663

URL: http://svn.gna.org/viewcvs/wesnoth?rev=53663&view=rev
Log:
switch effect multiplication to double and add extensive comment (re: r53615)

Modified:
    trunk/src/unit_abilities.cpp

Modified: trunk/src/unit_abilities.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_abilities.cpp?rev=53663&r1=53662&r2=53663&view=diff
==============================================================================
--- trunk/src/unit_abilities.cpp (original)
+++ trunk/src/unit_abilities.cpp Mon Mar 26 07:01:16 2012
@@ -882,15 +882,23 @@
                effect_list_.push_back(set_effect);
        }
 
-       float multiplier = 1.0f;
-       float divisor = 1.0f;
+       /* Do multiplication with floating point values rather than integers
+        * We want two places of precision for each multiplier
+        * Using integers multiplied by 100 to keep precision causes overflow
+        *   after 3-4 abilities for 32-bit values and ~8 for 64-bit
+        * Avoiding the overflow by dividing after each step introduces 
rounding errors
+        *   that may vary depending on the order effects are applied
+        * As the final values are likely <1000 (always true for mainline), 
loss of less significant digits is not an issue
+        */
+       double multiplier = 1.0;
+       double divisor = 1.0;
        std::map<std::string,individual_effect>::const_iterator e, e_end;
        for (e = values_mul.begin(), e_end = values_mul.end(); e != e_end; ++e) 
{
-               multiplier *= e->second.value/100.0f;           
+               multiplier *= e->second.value/100.0;            
                effect_list_.push_back(e->second);
        }
        for (e = values_div.begin(), e_end = values_div.end(); e != e_end; ++e) 
{
-               divisor *= e->second.value/100.0f;
+               divisor *= e->second.value/100.0;
                effect_list_.push_back(e->second);
        }
        int addition = 0;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to