glib uses wrong prefix for base-2 units



Hello,

g_format_size_for_display uses the wrong prefixes for units that are
counted in power of two. The SI defines following prefixes:

k = 1000
M = 1000 k
G = 1000 M
...

Please use the IEC standard for binary prefixes:

Ki = 1024
Mi = 1024 Ki
Gi = 1024 Mi
...

More information can be found here:
http://physics.nist.gov/cuu/Units/binary.html
http://en.wikipedia.org/wiki/Binary_prefix

I have appended a patch for it. Here are some reasons why you should
apply this patch:

* It is the correct usage of the standards.

* It would avoid ambiguity and consumer confusion:
http://en.wikipedia.org/wiki/Binary_prefix#Consumer_confusion

* The users want it. E.g. look at brainstorm:
http://brainstorm.ubuntu.com/idea/4114/
http://brainstorm.ubuntu.com/idea/17839/

* The Linux kernel uses it (man units).

Cheers,
Benjamin
diff -pruN glib2.0-2.21.1.orig/glib/gfileutils.c glib2.0-2.21.1/glib/gfileutils.c
--- glib2.0-2.21.1.orig/glib/gfileutils.c	2009-06-03 01:04:20.000000000 +0200
+++ glib2.0-2.21.1/glib/gfileutils.c	2009-06-03 23:04:41.000000000 +0200
@@ -1714,11 +1714,11 @@ g_build_filename (const gchar *first_ele
  * @size: a size in bytes.
  * 
  * Formats a size (for example the size of a file) into a human readable string.
- * Sizes are rounded to the nearest size prefix (KB, MB, GB) and are displayed 
- * rounded to the nearest  tenth. E.g. the file size 3292528 bytes will be
- * converted into the string "3.1 MB".
+ * Sizes are rounded to the nearest size prefix (KiB, MiB, GiB) and are
+ * displayed rounded to the nearest tenth. E.g. the file size 3292528 bytes
+ * will be converted into the string "3.1 MiB".
  *
- * The prefix units base is 1024 (i.e. 1 KB is 1024 bytes).
+ * The prefix units base is 1024 (i.e. 1 KiB is 1024 bytes).
  *
  * This string should be freed with g_free() when not needed any longer.
  *
@@ -1739,17 +1739,17 @@ g_format_size_for_display (goffset size)
       if (size < (goffset) MEGABYTE_FACTOR)
 	{
 	  displayed_size = (gdouble) size / KILOBYTE_FACTOR;
-	  return g_strdup_printf (_("%.1f KB"), displayed_size);
+	  return g_strdup_printf (_("%.1f KiB"), displayed_size);
 	}
       else if (size < (goffset) GIGABYTE_FACTOR)
 	{
 	  displayed_size = (gdouble) size / MEGABYTE_FACTOR;
-	  return g_strdup_printf (_("%.1f MB"), displayed_size);
+	  return g_strdup_printf (_("%.1f MiB"), displayed_size);
 	}
       else
 	{
 	  displayed_size = (gdouble) size / GIGABYTE_FACTOR;
-	  return g_strdup_printf (_("%.1f GB"), displayed_size);
+	  return g_strdup_printf (_("%.1f GiB"), displayed_size);
 	}
     }
 }

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]