From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/523 Path: news.gmane.org!not-for-mail From: Pascal Cuoq Newsgroups: gmane.linux.lib.musl.general Subject: Re: Undefined behavior in atoi() Date: Tue, 8 Nov 2011 06:43:45 +0100 Message-ID: References: <20111106212145.GO132@brightrain.aerifal.cx> <20111108034404.GP132@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d044472c1a835a004b132a7e6 X-Trace: dough.gmane.org 1320731043 5884 80.91.229.12 (8 Nov 2011 05:44:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Nov 2011 05:44:03 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-524-gllmg-musl=m.gmane.org@lists.openwall.com Tue Nov 08 06:43:59 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1RNeTX-0002DW-BG for gllmg-musl@lo.gmane.org; Tue, 08 Nov 2011 06:43:59 +0100 Original-Received: (qmail 27801 invoked by uid 550); 8 Nov 2011 05:43:58 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 27788 invoked from network); 8 Nov 2011 05:43:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=430nWiu/FZcBIshVzyqje5hwNX7dsE67GAl6aczShm0=; b=JcsHjy6Sq+jvJ6bEA6J/76J4ZVb+b50G2WEGPPup1+jPmUInMN2jHyZXI/GxO52fyM xNlCDogmfJKqIE72DI0WSEOkoLuEwbLnhJC/hu9HQrQb3wPUQA9HDRBHWfvuP7H7WiTA aVoj8Uloqxh9OTHSbf17RcoQAAJMF2WhERwKU= In-Reply-To: <20111108034404.GP132@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:523 Archived-At: --f46d044472c1a835a004b132a7e6 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Nov 8, 2011 at 4:44 AM, Rich Felker wrote: > On Sun, Nov 06, 2011 at 11:28:41PM +0100, Pascal Cuoq wrote: > > > I was looking at implementations for strtod() (long story for another > time) > > It should be noted that the current implementation is not correct. > There's lots of loss-of-precision. > So I have seen, but if it's possible to do better for the objectives of musl, I do not know how. David M. Gay's code is efficient but it's not portable, and the other implementation I found (provided as part of Tcl and Ruby for instance) is only to a few ULPs too. I am going to write my own, with multi-precision integers (that I already rely on for other things). I am hoping that by letting ldexp take care of denormals and infinites, it will be simple. > Glad to hear you found the code pleasant, at least that part. Some > things (like floating point in vfprintf.c) are a bit ugly.. :) > I did look at the floating-point part in vfprintf.c, because of the claim on musl's website that printing floating-point numbers was correct. I have had trouble with floating-point to decimal conversion too, but I cheated a little there by inventing by own format: http://blog.frama-c.com/index.php?post/2011/10/29/A-portable-OCaml-function-to-print-floats Pascal --f46d044472c1a835a004b132a7e6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, Nov 8, 2011 at 4:44 AM, Rich Felker <dalias@aerifal.cx> wrote:
On Sun, Nov 06, 2011 at 11:28:41PM +0100, Pascal Cuoq wro= te:

> I was looking at implementations for strtod() (long story for another = time)

It should be noted that the current implementation is not correct. There's lots of loss-of-precision.

= So I have seen, but if it's possible to do better for the objectives of= musl,
I do not know how. David M. Gay's code is efficient bu= t it's not portable,
and the other implementation I found (provided as part of Tcl and Ruby=
for instance) is only to a few ULPs too.

I am going to write my own, with multi-precision integers (that I already=
rely on for other things). I am hoping that by letting ldexp take care=
of denormals and infinites, it will be simple.
=A0
Glad to hear you found the code pleasant, at least that part. Some
things (like floating point in vfprintf.c) are a bit ugly.. :)

I did look at the floating-point part in vfprintf.c= , because of
the claim on musl's website that printing=A0floa= ting-point numbers
was correct. I have had trouble with floating-point
to decim= al conversion too, but I cheated a little there by inventing
by o= wn format:


Pascal

--f46d044472c1a835a004b132a7e6--