Skip to content

Commit

Permalink
Merge #9: Add note about IEEE 1541 definitions of units
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Sep 28, 2016
2 parents 3c3c509 + 258a4b1 commit 6c3a989
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,35 @@ Human friendly input/output (text formatting) on the command line based on the P

.. [[[end]]]
Note on units used
------------------

This package uses the traditional units based on powers of two. These units are
still used in Microsoft Windows' graphical user interface and in other
software.

+--------+----------------+
| Unit | Value in bytes |
+--------+----------------+
| ``KB`` | 1024 |
+--------+----------------+
| ``MB`` | 1048576 |
+--------+----------------+
| ``GB`` | 1073741824 |
+--------+----------------+
| ``TB`` | 1099511627776 |
+--------+----------------+
| etc | |
+--------+----------------+

The standard IEEE 1541, used by many hardware and software vendors today,
contradicts this definition, using power of 10 units instead for ``kB``,
``MB``, ``GB`` and so on. These definitions are often referred to as SI
formatting, due to their similarity with the metric system. Thankfully, IEEE
1541 also unambigously defines ``KiB``, ``MiB`` (etc) to the values based on
powers of 2. This module does not yet support these units.


Contact
-------

Expand Down
5 changes: 4 additions & 1 deletion humanfriendly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def format_size(num_bytes, keep_width=False, correct=False):
``False`` if they can be stripped.
:returns: The corresponding human readable file size (a string).
This function supports ranges from kilobytes to terabytes.
This function supports ranges from kilobytes to terabytes. It only supports
the definitions that are based on powers of 2.
Some examples:
Expand Down Expand Up @@ -157,6 +158,8 @@ def parse_size(size, correct=False):
:returns: The corresponding size in bytes (an integer).
:raises: :exc:`InvalidSize` when the input can't be parsed.
This function only supports the definitions that are based on powers of 2.
Some examples:
>>> from humanfriendly import parse_size
Expand Down

0 comments on commit 6c3a989

Please sign in to comment.