[master 1/1] Convert float to str for better precision in Size
jkonecny12
installerbot-noreply at redhat.com
Fri Sep 18 12:11:17 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
---
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/66e4454db1f313375cc1feec684dc0921684076a
More information about the anaconda-patches
mailing list