X-Loop: help-debbugs@HIDDEN Subject: bug#16987: Bad default mantissa width for ~g format string Resent-From: David Kastrup <dak@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-guile@HIDDEN Resent-Date: Tue, 11 Mar 2014 13:41:02 +0000 Resent-Message-ID: <handler.16987.B.13945452501010 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: report 16987 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 16987 <at> debbugs.gnu.org X-Debbugs-Original-To: bug-guile@HIDDEN Received: via spool by submit <at> debbugs.gnu.org id=B.13945452501010 (code B ref -1); Tue, 11 Mar 2014 13:41:02 +0000 Received: (at submit) by debbugs.gnu.org; 11 Mar 2014 13:40:50 +0000 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> 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-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
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: David Kastrup <dak@HIDDEN> Subject: bug#16987: Acknowledgement (Bad default mantissa width for ~g format string) Message-ID: <handler.16987.B.13945452501010.ack <at> debbugs.gnu.org> References: <87lhwg7t0n.fsf@HIDDEN> X-Gnu-PR-Message: ack 16987 X-Gnu-PR-Package: guile Reply-To: 16987 <at> debbugs.gnu.org Date: Tue, 11 Mar 2014 13:41:02 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. Your message has been sent to the package maintainer(s): bug-guile@HIDDEN If you wish to submit further information on this problem, please send it to 16987 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 16987: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D16987 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
X-Loop: help-debbugs@HIDDEN Subject: bug#16987: Bad default mantissa width for ~g format string Resent-From: Mark H Weaver <mhw@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-guile@HIDDEN Resent-Date: Tue, 11 Mar 2014 15:23:02 +0000 Resent-Message-ID: <handler.16987.B16987.139455132712585 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: followup 16987 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: David Kastrup <dak@HIDDEN> Cc: 16987 <at> debbugs.gnu.org Received: via spool by 16987-submit <at> debbugs.gnu.org id=B16987.139455132712585 (code B ref 16987); Tue, 11 Mar 2014 15:23:02 +0000 Received: (at 16987) by debbugs.gnu.org; 11 Mar 2014 15:22:07 +0000 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> 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-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
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.