* [gentoo-portage-dev] [PATCH] localized_size(): fix rounding in Python 2.
@ 2014-08-06 17:12 Michał Górny
2014-08-11 21:06 ` Michał Górny
0 siblings, 1 reply; 2+ messages in thread
From: Michał Górny @ 2014-08-06 17:12 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Michał Górny
In Python 2, the '/' division operator defaults to integer division when
given integer argument. Therefore, the calculated size is trimmed before
we attempt to round it up. Instead, convert it to float first to
guarantee floating point division.
---
pym/portage/localization.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pym/portage/localization.py b/pym/portage/localization.py
index 7d30b59..77417ba 100644
--- a/pym/portage/localization.py
+++ b/pym/portage/localization.py
@@ -35,6 +35,6 @@ def localized_size(num_bytes):
"""
# always round up, so that small files don't end up as '0 KiB'
- num_kib = math.ceil(num_bytes / 1024)
+ num_kib = math.ceil(float(num_bytes) / 1024)
formatted_num = locale.format('%d', num_kib, grouping=True)
return (_unicode_decode(formatted_num, encoding=_encodings['stdio']) + ' KiB')
--
2.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] localized_size(): fix rounding in Python 2.
2014-08-06 17:12 [gentoo-portage-dev] [PATCH] localized_size(): fix rounding in Python 2 Michał Górny
@ 2014-08-11 21:06 ` Michał Górny
0 siblings, 0 replies; 2+ messages in thread
From: Michał Górny @ 2014-08-11 21:06 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 438 bytes --]
Dnia 2014-08-06, o godz. 19:12:40
Michał Górny <mgorny@gentoo.org> napisał(a):
> In Python 2, the '/' division operator defaults to integer division when
> given integer argument. Therefore, the calculated size is trimmed before
> we attempt to round it up. Instead, convert it to float first to
> guarantee floating point division.
This one got superseded by the __future__ division patch.
--
Best regards,
Michał Górny
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 949 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-11 21:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-06 17:12 [gentoo-portage-dev] [PATCH] localized_size(): fix rounding in Python 2 Michał Górny
2014-08-11 21:06 ` Michał Górny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox