wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src unit.cpp unit_types.cpp util.hpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src unit.cpp unit_types.cpp util.hpp
Date: Sat, 23 Apr 2005 16:22:59 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    05/04/23 20:22:59

Modified files:
        src            : unit.cpp unit_types.cpp util.hpp 

Log message:
        Remove some non-portable divisions.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.cpp.diff?tr1=1.142&tr2=1.143&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.cpp.diff?tr1=1.97&tr2=1.98&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/util.hpp.diff?tr1=1.21&tr2=1.22&r1=text&r2=text

Patches:
Index: wesnoth/src/unit.cpp
diff -u wesnoth/src/unit.cpp:1.142 wesnoth/src/unit.cpp:1.143
--- wesnoth/src/unit.cpp:1.142  Fri Apr 22 20:58:35 2005
+++ wesnoth/src/unit.cpp        Sat Apr 23 20:22:58 2005
@@ -1,4 +1,4 @@
-/* $Id: unit.cpp,v 1.142 2005/04/22 20:58:35 ott Exp $ */
+/* $Id: unit.cpp,v 1.143 2005/04/23 20:22:58 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1049,15 +1049,7 @@
                                //a percentage on the end means increase by 
that many percent
                                if(increase_total[increase_total.size()-1] == 
'%') {
                                        const std::string 
inc(increase_total.begin(),increase_total.end()-1);
-                                       //work around implementation-defined 
integer division
-                                       //involving negative numbers
-                                       int increment = atoi(inc.c_str());
-                                       int sign = 1;
-                                       if (increment < 0) {
-                                               increment = -increment;
-                                               sign = -1;
-                                       }
-                                       maxHitpoints_ += 
((maxHitpoints_*increment)/100) * sign;
+                                       maxHitpoints_ += div100(maxHitpoints_ * 
atoi(inc.c_str()));
                                } else {
                                        maxHitpoints_ += 
atoi(increase_total.c_str());
                                }
@@ -1093,7 +1085,7 @@
 
                                if(increase[increase.size()-1] == '%') {
                                        const std::string 
inc(increase.begin(),increase.end()-1);
-                                       maxMovement_ += 
(maxMovement_*atoi(inc.c_str()))/100;
+                                       maxMovement_ += div100(maxMovement_ * 
atoi(inc.c_str()));
                                } else {
                                        maxMovement_ += atoi(increase.c_str());
                                }
@@ -1119,7 +1111,7 @@
 
                                if(increase[increase.size()-1] == '%') {
                                        const std::string 
inc(increase.begin(),increase.end()-1);
-                                       maxExperience_ += 
(maxExperience_*atoi(inc.c_str()))/100;
+                                       maxExperience_ += div100(maxExperience_ 
* atoi(inc.c_str()));
                                } else {
                                        maxExperience_ += 
atoi(increase.c_str());
                                }
Index: wesnoth/src/unit_types.cpp
diff -u wesnoth/src/unit_types.cpp:1.97 wesnoth/src/unit_types.cpp:1.98
--- wesnoth/src/unit_types.cpp:1.97     Thu Apr 21 20:49:16 2005
+++ wesnoth/src/unit_types.cpp  Sat Apr 23 20:22:59 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.cpp,v 1.97 2005/04/21 20:49:16 gruikya Exp $ */
+/* $Id: unit_types.cpp,v 1.98 2005/04/23 20:22:59 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -297,8 +297,7 @@
                
                if(increase_damage[increase_damage.size()-1] == '%') {
                        const std::string 
inc(increase_damage.begin(),increase_damage.end()-1);
-                       const int percent = atoi(inc.c_str());
-                       increase = (damage_*percent)/100;
+                       increase = div100(damage_ * atoi(inc.c_str()));
                } else {
                        increase = atoi(increase_damage.c_str());
                }
Index: wesnoth/src/util.hpp
diff -u wesnoth/src/util.hpp:1.21 wesnoth/src/util.hpp:1.22
--- wesnoth/src/util.hpp:1.21   Wed Feb  9 23:32:01 2005
+++ wesnoth/src/util.hpp        Sat Apr 23 20:22:59 2005
@@ -1,4 +1,4 @@
-/* $Id: util.hpp,v 1.21 2005/02/09 23:32:01 ydirson Exp $ */
+/* $Id: util.hpp,v 1.22 2005/04/23 20:22:59 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -40,6 +40,11 @@
 template<typename T>
 inline bool is_even(T num) { return !is_odd(num); }
 
+// guarantees portable results for division by 100
+inline int div100(int num) {
+  return num < 0 ? -((-num) / 100) : num / 100;
+}
+
 struct bad_lexical_cast {};
 
 template<typename To, typename From>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]