unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Converting an Integer into Human Readable String
Date: Sat, 09 Apr 2011 11:46:34 +0300	[thread overview]
Message-ID: <83bp0fu80l.fsf@gnu.org> (raw)
In-Reply-To: <87vcyphswl.fsf@kuiper.lan.informatimago.com>

> From: "Pascal J. Bourguignon" <pjb@informatimago.com>
> Date: Fri, 08 Apr 2011 13:41:30 +0200
> 
> Instead, you could have had some fun, and implement yourself the
> required function.   Well, now you've got only what you merit, here I
> had all the fun, you can have the function:
> 
>     (format-human-readable-big-number 123456789012
>                                       *normal-format*
>                                       *exceptional-format*
>                                        "B" t :binary)
>     --> "  114.978 GiB"

That's very impressive, but at closer look, I found the following
problems with this implementation:

 . It cannot be evaluated in Emacs Lisp without commenting out the
   part between "#|" and "|#".

 . It cannot be evaluated on a 32-bit machine without commenting out
   some parts of the integer test values in the test harness, due to
   integer overflows.

 . When the last argument is :binary, it produces wrong results for
   numbers between 1000*2^N and 1023*2^N.  E.g.,

    (format-human-readable-big-number 1023  "%.1f" "%13.3e" "B" t :binary)
      => "   1.023e+003 B"

   whereas I'd expect "1023 B" instead.

 . It always produces results with a fixed number of digits after the
   decimal, determined by the value of *normal-format*.  Thus, with a
   format of "%.1f" it will always produce 1 digit after the decimal,
   even if that digit is zero:

    (format-human-readable-big-number 900  "%.1f" "%13.3e" "B" t :binary)
      => "900.0 B"

   which is IMO ugly; "ls -lh" produces just "900" in this case.  This
   cannot be remedied by using "%.0f" as the normal format, because
   then it will always round to the nearest integral value, and the
   fractions will never be shown; again, this is different from "ls -lh".



  parent reply	other threads:[~2011-04-09  8:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-07 10:02 Converting an Integer into Human Readable String Nordlöw
2011-04-07 11:34 ` Deniz Dogan
2011-04-07 12:04   ` Eli Zaretskii
2011-04-07 11:52 ` Eli Zaretskii
2011-04-07 12:51 ` Drew Adams
2011-04-07 17:43   ` Eli Zaretskii
2011-04-07 18:13     ` Drew Adams
2011-04-07 18:35       ` Eli Zaretskii
2011-04-07 18:51         ` Drew Adams
2011-04-07 20:10           ` Eli Zaretskii
2011-04-07 18:44       ` Eli Zaretskii
2011-04-07 19:01         ` Thierry Volpiatto
     [not found]         ` <mailman.17.1302204476.27822.help-gnu-emacs@gnu.org>
2011-04-08  6:35           ` Klaus Straubinger
2011-04-08  7:07             ` Thierry Volpiatto
2011-04-08  8:29               ` Eli Zaretskii
2011-04-08  9:38                 ` Thierry Volpiatto
2011-04-08 11:41 ` Pascal J. Bourguignon
2011-04-08 15:19   ` Eli Zaretskii
2011-04-08 19:12     ` Thierry Volpiatto
2011-04-08 21:36       ` Eli Zaretskii
2011-04-09  5:24         ` Thierry Volpiatto
2011-04-09  8:46   ` Eli Zaretskii [this message]
     [not found]   ` <mailman.1.1302338931.20547.help-gnu-emacs@gnu.org>
2011-04-09  9:33     ` Pascal J. Bourguignon
2011-04-09 12:13       ` Eli Zaretskii
     [not found]       ` <mailman.0.1302351322.29796.help-gnu-emacs@gnu.org>
2011-04-11 15:31         ` Ted Zlatanov
2011-04-11 16:57           ` Eli Zaretskii
2011-05-12 19:30           ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83bp0fu80l.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).