GNU bug report logs - #16987
Bad default mantissa width for ~g format string

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guile; Reported by: David Kastrup <dak@HIDDEN>; dated Tue, 11 Mar 2014 13:41:02 UTC; Maintainer for guile is bug-guile@HIDDEN.

Message received at 16987 <at> debbugs.gnu.org:


Received: (at 16987) by debbugs.gnu.org; 11 Mar 2014 15:22:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Mar 11 11:22:07 2014
Received: from localhost ([127.0.0.1]:33473 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1WNOVK-0003Gu-T4
	for submit <at> debbugs.gnu.org; Tue, 11 Mar 2014 11:22:07 -0400
Received: from world.peace.net ([96.39.62.75]:51912)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <mhw@HIDDEN>) id 1WNOV9-0003GH-Md
 for 16987 <at> debbugs.gnu.org; Tue, 11 Mar 2014 11:22:05 -0400
Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com
 ([209.6.91.212] helo=yeeloong.lan)
 by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.72) (envelope-from <mhw@HIDDEN>)
 id 1WNOV2-0008A2-B8; Tue, 11 Mar 2014 11:21:48 -0400
From: Mark H Weaver <mhw@HIDDEN>
To: David Kastrup <dak@HIDDEN>
Subject: Re: bug#16987: Bad default mantissa width for ~g format string
References: <87lhwg7t0n.fsf@HIDDEN>
Date: Tue, 11 Mar 2014 11:21:36 -0400
In-Reply-To: <87lhwg7t0n.fsf@HIDDEN> (David Kastrup's message of
 "Tue, 11 Mar 2014 14:40:40 +0100")
Message-ID: <87y50g92wv.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 16987
Cc: 16987 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)

David Kastrup <dak@HIDDEN> writes:

> scheme@(guile-user)> (format #f "~g" (/ 1e100 3))
> $19 = "3333333333333333000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0    "
>
> That, frankly, is pretty ludicrous.  The reserved mantissa width should
> at least be constrained to the actually available precision of the data
> type.

Agreed.

> If it isn't, there is no useful way to output a variable with
> minimal width.  Using ~S instead results in the much more reasonable
> "3.333333333333333e99" but it will not convert fractions to a floating
> point representation:
>
> scheme@(guile-user)> (format #f "~g" (/ 10000000000000000000000000000000 3))
> $22 = "3333333333333333600000000000000.0    "
> scheme@(guile-user)> (format #f "~S" (/ 10000000000000000000000000000000 3))
> $23 = "10000000000000000000000000000000/3"
> scheme@(guile-user)> 

As a workaround, you can force decimal output with ~S by converting the
exact fraction to an inexact floating point number before passing it to
'format', using 'exact->inexact':

  scheme@(guile-user)> (format #f "~S" (exact->inexact (/ 10000000000000000000000000000000 3)))
  $4 = "3.3333333333333336e30"

Note that 'exact->inexact' works even if the number passed to it is
already inexact, in which case it's a no-op.

At some point we'll make ~g do the right thing for exact fractions, so
that the last digit printed is a 3, not 6.  For now, it can't be helped
because the value is being rounded twice: once in the conversion to
inexact binary, and again when converting from binary to decimal.

    Thanks,
      Mark




Information forwarded to bug-guile@HIDDEN:
bug#16987; Package guile. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 11 Mar 2014 13:40:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Mar 11 09:40:50 2014
Received: from localhost ([127.0.0.1]:32798 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1WNMvJ-0000GE-UI
	for submit <at> debbugs.gnu.org; Tue, 11 Mar 2014 09:40:50 -0400
Received: from eggs.gnu.org ([208.118.235.92]:39851)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <dak@HIDDEN>) id 1WNMvF-0000G3-Sz
 for submit <at> debbugs.gnu.org; Tue, 11 Mar 2014 09:40:46 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <dak@HIDDEN>) id 1WNMvE-0005yn-KT
 for submit <at> debbugs.gnu.org; Tue, 11 Mar 2014 09:40:45 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_RP_MATCHES_RCVD
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:46882)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <dak@HIDDEN>)
 id 1WNMvE-0005yj-He
 for submit <at> debbugs.gnu.org; Tue, 11 Mar 2014 09:40:44 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41569)
 by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <dak@HIDDEN>)
 id 1WNMvD-0008CA-KI
 for bug-guile@HIDDEN; Tue, 11 Mar 2014 09:40:44 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <dak@HIDDEN>) id 1WNMvB-0005yG-J5
 for bug-guile@HIDDEN; Tue, 11 Mar 2014 09:40:43 -0400
Received: from fencepost.gnu.org ([2001:4830:134:3::e]:35859)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <dak@HIDDEN>)
 id 1WNMvB-0005y9-90
 for bug-guile@HIDDEN; Tue, 11 Mar 2014 09:40:41 -0400
Received: from localhost ([127.0.0.1]:43032 helo=lola)
 by fencepost.gnu.org with esmtp (Exim 4.71)
 (envelope-from <dak@HIDDEN>) id 1WNMvA-0003s6-TX
 for bug-guile@HIDDEN; Tue, 11 Mar 2014 09:40:41 -0400
Received: by lola (Postfix, from userid 1000)
 id 70AB9E278D; Tue, 11 Mar 2014 14:40:40 +0100 (CET)
From: David Kastrup <dak@HIDDEN>
To: bug-guile@HIDDEN
Subject: Bad default mantissa width for ~g format string
Date: Tue, 11 Mar 2014 14:40:40 +0100
Message-ID: <87lhwg7t0n.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)


scheme@(guile-user)> (format #f "~g" (/ 1e100 3))
$19 = "3333333333333333000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0    "

That, frankly, is pretty ludicrous.  The reserved mantissa width should
at least be constrained to the actually available precision of the data
type.  If it isn't, there is no useful way to output a variable with
minimal width.  Using ~S instead results in the much more reasonable
"3.333333333333333e99" but it will not convert fractions to a floating
point representation:

scheme@(guile-user)> (format #f "~g" (/ 10000000000000000000000000000000 3))
$22 = "3333333333333333600000000000000.0    "
scheme@(guile-user)> (format #f "~S" (/ 10000000000000000000000000000000 3))
$23 = "10000000000000000000000000000000/3"
scheme@(guile-user)> 

-- 
David Kastrup




Acknowledgement sent to David Kastrup <dak@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-guile@HIDDEN. Full text available.
Report forwarded to bug-guile@HIDDEN:
bug#16987; Package guile. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

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