From owner-svn-soc-all@FreeBSD.ORG Tue Jun 3 01:08:23 2014 Return-Path: Delivered-To: svn-soc-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CFBFCDB; Tue, 3 Jun 2014 01:08:23 +0000 (UTC) Received: from mail-wg0-x232.google.com (mail-wg0-x232.google.com [IPv6:2a00:1450:400c:c00::232]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0F69F2804; Tue, 3 Jun 2014 01:08:22 +0000 (UTC) Received: by mail-wg0-f50.google.com with SMTP id x12so5863806wgg.33 for ; Mon, 02 Jun 2014 18:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=zPGEeeGwoAP0610JX2D50+a2Ve8hI/CtH5Vb2aH94D8=; b=dQcxRAR4/NuCjdk/+zgxPWC2my2LeX194EPqHZhJf7FczxulKQ3Gbhtcob91tXUVzO 11LSyyTT4tlZIrutBT7TuTpDb9J0i3wzGOjqQthZPz7B8qT5rYiPd5oLGDlMgDDSJ7uw JBkQqlGLFuA2Vy+TWy5sPeKvro4w9MJW4dbaUoPAb0YQQ/L6ndaWuKAxcKIWC/nBMXJg XUfuHMjSGEX45z1pj/18Kt+K+E2piP+UE+KtnVFM0dv0aidVtZ2rcFdaUx4MznETYbTa EQlBCtt8iz1RLzuYECrmM7BqTBqZ1+q8xJbV2pA0QsPUNRHYUNiQHlMO+3FJ1eWYEBZ+ gZcA== MIME-Version: 1.0 X-Received: by 10.180.73.66 with SMTP id j2mr4269453wiv.36.1401757701176; Mon, 02 Jun 2014 18:08:21 -0700 (PDT) Received: by 10.194.185.239 with HTTP; Mon, 2 Jun 2014 18:08:21 -0700 (PDT) In-Reply-To: <20140602220616.GC2587@FreeBSD.org> References: <201406020100.s5210uAh043824@socsvn.freebsd.org> <20140602220616.GC2587@FreeBSD.org> Date: Mon, 2 Jun 2014 22:08:21 -0300 Message-ID: Subject: Re: socsvn commit: r268941 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua/src From: Pedro Arthur To: "Wojciech A. Koszek" Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18 Cc: svn-soc-all@freebsd.org, pedrosouza@freebsd.org X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jun 2014 01:08:23 -0000 Hi, libstand doesn't have any function to parse floating point numbers, it can parse only integers. The lua interpreter consider all numbers as floating point (double) and uses the strtod function, I also searched through the ficl interpreter to see which function it uses to parse numbers but I found that it parses only integers too. By he way libstand also can't convert any floating point to string. 2014-06-02 19:06 GMT-03:00 Wojciech A. Koszek : > On Mon, Jun 02, 2014 at 01:00:56AM +0000, pedrosouza@freebsd.org wrote: > > Author: pedrosouza > > Date: Mon Jun 2 01:00:55 2014 > > New Revision: 268941 > > URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=268941 > > > > Log: > > Implemented number parsing for lua > > > > Modified: > > soc2014/pedrosouza/lua_loader/head/sys/boot/lua/src/lstd.c > > > > Pedro, > > Why was this necessary? Which part of Lua requires that? > > If it's strictly needed, was the strtod() implementation present in > libstand? I think the preference would be to use whatever was in libstand. > > Thanks, > > Wojciech > > > Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/src/lstd.c > > > ============================================================================== > > --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/src/lstd.c > Mon Jun 2 00:21:42 2014 (r268940) > > +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/src/lstd.c > Mon Jun 2 01:00:55 2014 (r268941) > > @@ -49,6 +49,96 @@ > > double > > strtod(const char *string, char **endPtr) > > { > > - printf("strtod not implemented!\n"); > > - return 0.; > > + int sign = 0; > > + int exp_sign = 0; > > + int has_num = 0; > > + int has_frac = 0; > > + int has_exp = 0; > > + unsigned long long num = 0; > > + unsigned long long exp = 0; > > + > > + double frac = 0; > > + double fm = 0.1; > > + double exp_m = 1; > > + double ret = 0; > > + > > + const char *ptr = string; > > + > > + while (isspace(*ptr)) ++ptr; > > + > > + if (*ptr == '-') > > + { > > + sign = 1; > > + ++ptr; > > + } else if (*ptr == '+') > > + ++ptr; > > + > > + while (isdigit(*ptr)) > > + { > > + num *= 10; > > + num += *ptr - '0'; > > + ++ptr; > > + ++has_num; > > + } > > + > > + if (*ptr == '.') > > + { > > + ++ptr; > > + while (isdigit(*ptr)) > > + { > > + frac += (double)(*ptr - '0') * fm; > > + fm *= 0.1; > > + ++ptr; > > + ++has_frac; > > + } > > + } > > + > > + if (has_frac == 0 && has_num == 0) > > + { > > + if (*endPtr) > > + *endPtr = (char*)string; > > + return 0.; > > + } > > + > > + ret = (double)num; > > + ret += frac; > > + > > + if (*ptr == 'e' || *ptr == 'E') > > + { > > + if (*endPtr) > > + *endPtr = (char*)ptr; > > + ++ptr; > > + if (*ptr == '-') > > + { > > + exp_sign = 1; > > + ++ptr; > > + } else if (*ptr == '+') > > + ++ptr; > > + > > + while (isdigit(*ptr)) > > + { > > + exp *= 10; > > + exp += *ptr - '0'; > > + ++ptr; > > + ++has_exp; > > + } > > + if (has_exp == 0) > > + return ret; > > + } > > + > > + if (*endPtr) > > + *endPtr = (char*)ptr; > > + > > + if (has_exp) > > + { > > + while (exp--) > > + exp_m *= 10; > > + if (exp_sign) > > + exp_m = 1./exp_m; > > + > > + } > > + if (sign) > > + ret = -ret; > > + > > + return ret * exp_m; > > } > > _______________________________________________ > > svn-soc-all@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/svn-soc-all > > To unsubscribe, send any mail to "svn-soc-all-unsubscribe@freebsd.org" > > -- > Wojciech A. Koszek > wkoszek@FreeBSD.czest.pl > http://FreeBSD.czest.pl/~wkoszek/ >