From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Problems with 'number->string' (was Re: propose deprecation of generalized-vector-*) Date: Mon, 18 Feb 2013 18:12:43 -0500 Message-ID: <87txp9nrmc.fsf_-_@tines.lan> References: <0F432FA1-CFF8-4A22-A477-5291A1B9925D@bluewin.ch> <87ip9mgzp4.fsf@gnu.org> <878v7m5xdh.fsf@pobox.com> <2E5FFE0D-9001-409C-BCD4-9EE3BF9883F0@bluewin.ch> <87mww0nu8l.fsf@pobox.com> <2D31D517-08F8-4D07-84DB-098E335AE0AD@bluewin.ch> <874nh9boqe.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1361229238 21830 80.91.229.3 (18 Feb 2013 23:13:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 Feb 2013 23:13:58 +0000 (UTC) Cc: guile-devel@gnu.org, Daniel Llorens To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Feb 19 00:14:20 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U7Zuc-0004WM-RH for guile-devel@m.gmane.org; Tue, 19 Feb 2013 00:14:18 +0100 Original-Received: from localhost ([::1]:35993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7ZuI-0002In-Lu for guile-devel@m.gmane.org; Mon, 18 Feb 2013 18:13:58 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:55681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7Ztg-0000WN-QK for guile-devel@gnu.org; Mon, 18 Feb 2013 18:13:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U7Zte-00089n-4q for guile-devel@gnu.org; Mon, 18 Feb 2013 18:13:20 -0500 Original-Received: from world.peace.net ([96.39.62.75]:51855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7Zte-00087e-0t for guile-devel@gnu.org; Mon, 18 Feb 2013 18:13:18 -0500 Original-Received: from 74-94-165-125-newengland.hfc.comcastbusiness.net ([74.94.165.125] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1U7ZtR-0007dR-8V; Mon, 18 Feb 2013 18:13:05 -0500 In-Reply-To: <874nh9boqe.fsf@pobox.com> (Andy Wingo's message of "Mon, 18 Feb 2013 16:55:53 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:15771 Archived-At: Andy Wingo writes: > On Wed 23 Jan 2013 13:20, Daniel Llorens writes: > >> scheme@(guile-user)> (f64vector-ref #s64(1 2 3) 0) >> $1 = #.# > > Here you are interpreting an int64 as a double, which should work, but > this printed result is really bizarre and looks like a bug in our number > printer. Mark? :) Yes, our number printer is seriously flawed and needs a rewrite. It prints subnormal[1] floats as "#.#", and even in typical cases often fails to print enough digits to get the same number back when you read it back in. Note that this also affects compiled code involving numbers, because the compiler serializes numbers using 'number->string'. For example, (* 1e-155 1e-155) returns #f at the REPL, because peval turns this into a constant which happens to be a subnormal. During assembly it serializes this to "#.#", and then 'string->number' returns #f. Also, 3.14159265358979323846264338327950288419716939937510582097494, if compiled, fails to produce the float closest to pi. (acos -1) works properly, but only because this expression is not currently folded to a constant by the compiler. I've already started work on this (based on "Printing Floating-Point Numbers Quickly and Accurately" by Burger and Dybvig) but got distracted. Mark [1] http://en.wikipedia.org/wiki/Subnormal_number