GNU bug report logs - #40855
integer-length 0 should be 1

Previous Next

Package: guile;

Reported by: Bengt Richter <bokr <at> bokr.com>

Date: Sat, 25 Apr 2020 21:17:01 UTC

Severity: normal

Merged with 40744

Full log


Message #10 received at submit <at> debbugs.gnu.org (full text, mbox):

From: <tomas <at> tuxteam.de>
To: bug-guile <at> gnu.org
Subject: Re: bug#40855: integer-length 0 should be 1
Date: Sun, 26 Apr 2020 10:23:15 +0200
[Message part 1 (text/plain, inline)]
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
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 5 years and 49 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.