Skip to content

Commit 258a4b1

Browse files
committed
Add note about IEEE 1541 definitions of units
1 parent 1021cac commit 258a4b1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,35 @@ Human friendly input/output (text formatting) on the command line based on the P
9191

9292
.. [[[end]]]
9393
94+
Note on units used
95+
------------------
96+
97+
This package uses the traditional units based on powers of two. These units are
98+
still used in Microsoft Windows' graphical user interface and in other
99+
software.
100+
101+
+--------+----------------+
102+
| Unit | Value in bytes |
103+
+--------+----------------+
104+
| ``KB`` | 1024 |
105+
+--------+----------------+
106+
| ``MB`` | 1048576 |
107+
+--------+----------------+
108+
| ``GB`` | 1073741824 |
109+
+--------+----------------+
110+
| ``TB`` | 1099511627776 |
111+
+--------+----------------+
112+
| etc | |
113+
+--------+----------------+
114+
115+
The standard IEEE 1541, used by many hardware and software vendors today,
116+
contradicts this definition, using power of 10 units instead for ``kB``,
117+
``MB``, ``GB`` and so on. These definitions are often referred to as SI
118+
formatting, due to their similarity with the metric system. Thankfully, IEEE
119+
1541 also unambigously defines ``KiB``, ``MiB`` (etc) to the values based on
120+
powers of 2. This module does not yet support these units.
121+
122+
94123
Contact
95124
-------
96125

humanfriendly/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def format_size(num_bytes, keep_width=False):
112112
``False`` if they can be stripped.
113113
:returns: The corresponding human readable file size (a string).
114114
115-
This function supports ranges from kilobytes to terabytes.
115+
This function supports ranges from kilobytes to terabytes. It only supports
116+
the definitions that are based on powers of 2.
116117
117118
Some examples:
118119
@@ -143,6 +144,8 @@ def parse_size(size):
143144
:returns: The corresponding size in bytes (an integer).
144145
:raises: :exc:`InvalidSize` when the input can't be parsed.
145146
147+
This function only supports the definitions that are based on powers of 2.
148+
146149
Some examples:
147150
148151
>>> from humanfriendly import parse_size

0 commit comments

Comments
 (0)