[master 9/21] Convert float to str for better precision in Size

vathpela installerbot-noreply at redhat.com
Wed Oct 7 20:50:44 UTC 2015


From: Jiri Konecny <jkonecny at redhat.com>

Convert float to string before it's converted to Decimal. This prevents
precision loss.

Related: rhbz#1224048
(cherry picked from commit 46e03fe2e69039e2b4a9f4432fb1e2e542641cd4)
---
 blivet/size.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/blivet/size.py b/blivet/size.py
index 1e40eb0..ba66dc2 100644
--- a/blivet/size.py
+++ b/blivet/size.py
@@ -305,23 +305,23 @@ def __reduce__(self):
     def __add__(self, other, context=None):
         # because float is not automatically converted to Decimal type
         if isinstance(other, float):
-            other = Decimal(other)
+            other = Decimal(str(other))
         return Size(Decimal.__add__(self, other))
 
     # needed to make sum() work with Size arguments
     def __radd__(self, other, context=None):
         if isinstance(other, float):
-            other = Decimal(other)
+            other = Decimal(str(other))
         return Size(Decimal.__radd__(self, other))
 
     def __sub__(self, other, context=None):
         if isinstance(other, float):
-            other = Decimal(other)
+            other = Decimal(str(other))
         return Size(Decimal.__sub__(self, other))
 
     def __mul__(self, other, context=None):
         if isinstance(other, float):
-            other = Decimal(other)
+            other = Decimal(str(other))
         return Size(Decimal.__mul__(self, other))
     __rmul__ = __mul__
 


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/e0cc136699d730c750637867d375e1e93b1fba64


More information about the anaconda-patches mailing list