Browse Source

avoid crashes with too-large numbers

David Rose 22 years ago
parent
commit
ee097fe7a8
1 changed files with 7 additions and 3 deletions
  1. 7 3
      direct/src/showbase/PythonUtil.py

+ 7 - 3
direct/src/showbase/PythonUtil.py

@@ -551,10 +551,14 @@ def formatElapsedSeconds(seconds):
     if seconds < 0:
         seconds = -seconds
         sign = '-'
-    seconds = (int)(seconds)
-    hours = (int)(seconds / (60 * 60))
+
+    # We use math.floor() instead of casting to an int, so we avoid
+    # problems with numbers that are too large to represent as
+    # type int.
+    seconds = math.floor(seconds)
+    hours = math.floor(seconds / (60 * 60))
     if hours > 36:
-        days = (int)((hours + 12) / 24)
+        days = math.floor((hours + 12) / 24)
         return "%s%d days" % (sign, days)
     
     seconds -= hours * (60 * 60)