From: Jiri Konecny <jkonecny(a)redhat.com>
Convert float to string before it's converted to Decimal. This prevents
precision loss.
Related: rhbz#1224048
---
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/66e4454db1f313375cc1feec684d...