On 09/26/2014 12:29 PM, Anne Mulhern wrote:
----- Original Message -----
> From: "David Lehman" <dlehman(a)redhat.com>
> To: anaconda-patches(a)lists.fedorahosted.org
> Sent: Friday, September 26, 2014 12:56:02 PM
> Subject: [blivet][PATCH] Use Decimal for math in Size.convertTo.
>
> Size.__div__ converts the Decimal result to a Size, which rounds its
> numerical argument (byte count) down to an integer. Size.convertTo is
> meant to retain precision.
> ---
> blivet/size.py | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/blivet/size.py b/blivet/size.py
> index 4c23c11..f2a32ce 100644
> --- a/blivet/size.py
> +++ b/blivet/size.py
> @@ -269,7 +269,7 @@ class Size(Decimal):
> check = _makeSpecs(prefix, abbr, False)
>
> if spec in check:
> - return Decimal(self / Decimal(factor))
> + return Decimal(Decimal(self) / Decimal(factor))
>
> return None
>
> --
> 1.9.3
>
_______________________________________________
anaconda-patches mailing list
anaconda-patches(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
Please add a differentiating test for this change.
Do you really need to cast the result? I would expect Decimal / Decimal to yield Decimal,
always.
You're right. I'll remove the outer/redundant cast.
- mulhern
P.S.
Size.__div__ has been disturbing me for a while:
4 gallons / 2 gallons = 2 (because the units cancel)
but in our code
4 MiB / 2 MiB = 2 B (which is clearly wrong)
so the less we use it, the better.
Agreed.
_______________________________________________
anaconda-patches mailing list
anaconda-patches(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches