unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: 40855@debbugs.gnu.org
Subject: bug#40855: integer-length 0 should be 1
Date: Sun, 26 Apr 2020 10:23:15 +0200	[thread overview]
Message-ID: <20200426082315.GA3611@tuxteam.de> (raw)
In-Reply-To: <20200425211540.GA10315@LionPure>

[-- Attachment #1: Type: text/plain, Size: 1214 bytes --]

On Sat, Apr 25, 2020 at 11:15:40PM +0200, Bengt Richter wrote:
> I'm hoping this is the right place to report this bug :)
> 
> To reproduce, guile -c '(format #t "~s\n" (integer-length 0))'
> Expected result if correct: 1
> Observed result: 0
> 
> The following is to support the opinion that 1 is the correct result,
> and to explore how integer "length" generalizes to other radixes and
> also signed number writing other than sign-magnitude.

Hm. This is a tough one. The problem is that there are several
possible extensions to zero, and no one is quite right. For example,
one could interpret (integer-length n) as one plus the base-two
logarithm of n (well, its integer part). Or, in mathy jargon,
1 + floor(log2 n).

In this case, the integer-length of zero would be minus infinity!

And for negative n, we'd be in hot water (or in complex analysis or
something :)

Thus, the simple definition given in the doc "For positive N this
is how many bits to the most significant one bit" looks like a wise
choice to me -- and this leads to a value of 0 for 0 (or some
infinity, if you keep searching for the one bit you'll never find,
if you insist to find an one.

Cheers
-- tomás

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

      reply	other threads:[~2020-04-26  8:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-25 21:15 bug#40855: integer-length 0 should be 1 Bengt Richter
2020-04-26  8:23 ` tomas [this message]

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/guile/

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

  git send-email \
    --in-reply-to=20200426082315.GA3611@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=40855@debbugs.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).